talideon.com

Platitudes and inanities

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.

Technorati Search Technorati Search Irish Bloggers

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.

Post a comment

All form information is optional, but it’s a good idea to fill in your name and email address if you want me to take your comment seriously.

Spammers, don’t bother posting crap down here. The site is set up so that legitimate search engines (Google, for instance) won’t index pages with comments on them. Posting crud here only means you’re wasting my time and patience. Shoo!

Real names, please. Please include!
Won’t be displayed. Please include!
Displayed, if present.