talideon.com

Blackout Ireland

May 24, 2005 at 3:52PM My C++ wrapper for the Expat XML parser.

Last year when I was writing Orpheus, I knocked out a C++ wrapper around Expat to make using it easier.

It consists of two classes. XMLParser is the Expat wrapper and sets up the event handlers and automates setup and tear-down of the parser itself. XMLEvtHandler consists of a set of callback methods triggered when some parsing event occurs, such as encountering a block of text, a start tag, or an end tag. You just subclass it, overriding any methods you need, and Robert’s your father’s brother.

It’s small and dead simple, and there’s next to no overhead except for that involved in the dynamic dispatch of the virtual members on the event handler class. In the big scheme of things, this overhead is minimal, though it could be got rid of completely if it were to be reimplemented using templates.

Download XMLParser and XMLEvtHandler here.

Comments

1 On May 23, 2007 at 8:41, Manjunatha Murthy wrote:

In usage instructions include a call to parser.Create before calling parser.EnableElementHandler. With out this null assertion fails in EnableElementHandler.