Writing software that uses XML
Date: 17/11/2004
Over the last few years I've been writing software I've begun using XML as a standard way to store applications settings and other data instead of some other 'proprietary' format (or *shudder* 'the registry'). And well I've gone through several of my own XML parsers, with various API's and methods of doing things. And now I've come 'home' in the sense that I have what I would imagine to be the final API that I will use for XML for the next 5 years at least.

There are 2 basic ways of parsing XML, a SAX style interface or a DOM tree interface. The SAX interface parses the XML and calls you back to tell you about the structure of the document. You only ever know about the current element that the parser is parsing. Whereas a DOM tree parser returns an in memory representation of the entire file in a tree structure that follows the format of the file. You can then modify that and write it back to disk.

The benifit of the DOM tree style parser is that you have access to the whole document at any given time, making the code far simpler. This also allows you to do pervasive changes to the whole document easily. Something that just saved me hours of coding. My particular API also allows you to read/write objects between C++ native types and XML using one set of serialization code. This is an important step towards very simple and robust XML code. You can't imagine how painful it is maintaining one set of code to read the XML into C++ types and then a completely separate set of code to write that back out to XML. The code itself is in GXmlTree.h and GXmlTree.cpp in Lgi if your interested.

I will certainly be using XML more now that it's trivially easy to load and save for me. For instance I'm migrating all the options files for my applications over to XML. Including Scribe v2.

All hail DOM parsers!
17/11/2004 12:13pm
Most of that statement went way over my head, but hell, if it makes life easier for you, I'm happy for you :)
Email (optional): (Will be HTML encoded to evade harvesting)
Remember username and/or email in a cookie.
Notify me of new posts in this thread via email.