John Ratcliff's Code Suppository

A place where I insert my code into the anus of the Internet.

 

Friday, October 23, 2009

Bug Fixes : Improvements to 'FastXml'



I made a couple of bug fixes and improvements to the 'FastXml' code snippets. 'FastXml' is a very tiny code snippet (less than 300 lines of code) that will parse an XML file *in place*. It is very fast and easy to use.

The 'in place' behavior is what makes it extremely powerful. When it calls back with elements, attributes, and data, those pointers are *persistent for the lifetime of the object*! That means you do not need to do any string copying and can cache those pointers directly if it speeds up your processing code.

The bugs which were fixed are as follows:

(1) The original version had a bug that if you had an element with no attributes or data it would fail. Example:

(2) The original version could not interpret XML comments. It now does, and will call you back with the comment data. Example:

The feature improvement is that it will now call you back when an element is closed. This is sometimes necessary when parsing data with hierarchical state. Not typically necessary if you are just parsing the XML data as a linear stream.

I have updated the source files and they are located here:

FastXml.h
FastXml.cpp