Dave Beckett's blog

Writing XML

2004-01-23 15:40

It seems Tim Bray has decided to write an XML writer in C called Genx that is lightweight and writes safe and efficient XML. I had to write a Exclusive Canonical XML writer for the RDF/XML parser in Raptor (which now contains several RDF parsers). in order to emit the XML literals from rdf:parseType="Literal". Raptor works on top of libxml2 or expat, so I couldn't rely on anything in the underlying XML parsers (only libxml2 has writing) so made a little XML writer of my own.

Looking at the draft API in genx.h so far the differences seem to be a harsh attitude to bad content - abort(), allows userdata, and allows a separate allocator to be used. It checks XML names I guess against 1.0 (with namespaces?), I also optionally allow the XML 1.1 draft names to be checked. Plus this was explicitly designed to be separate whereas my writer uses the other parts of Raptor that provide XML QNames and URIs.

I think he'll find like I did, that you'll have to write or use a bunch of Unicode/UTF-8 code, which is tedious to do and another load of code that should just be reused by everyone. I didn't find a decent libunicode, libutf8 or liburi either in C, so Raptor has enough of them for me to get by.

The details of the Raptor API, classes and how it is used are given in the Raptor API