I know of at least three light weight C++ XML parsers: RapidXML, TinyXML and PugiXML. However, all three use a DOM based interface (ie, they build their own in-memory representation of the XML document and then provide an interface to traverse and manipulate it). For most situations that I have to deal with, I much prefer the SAX interface (where the parser just spits out a stream of events like start-of-tag, and the application code is responsible for doing whatever it wants based on those events).
Can anyone recommend a light weight C++ XML library with a SAX interface?
Edit: I should also note the Microsoft XmlLite library, which does use a SAX interface (well, actually a "pull" interface which is possibly even better). Unfortunately, it's ruled out for me at the moment since as far as I know it's closed source and Windows only (please correct me if I'm wrong on this).
A SAX parser, however, is much more space efficient in case of a big input document (because it creates no internal structure). What's more, it runs faster and is easier to learn than DOM parser because its API is really simple.
Well parsing XML is not an easy task. Its basic structure is a tree with any node in tree capable of holding a container which consists of an array of more trees.
1)SAX is an event-driven push model for processing XML. It is not a W3C standard, 2)Rather than building a tree representation of an entire document as DOM does, a SAX parser fires off a series of events as it reads through the document. 4) you have to keep track of where the parser is in the document hierarchy.
The Oracle XML parser for C reads an XML document and uses DOM or SAX APIs to provide programmatic access to its content and structure. You can use the parser in validating or nonvalidating mode. This chapter assumes that you are familiar with the following technologies: Document Object Model (DOM).
I've used expat when I needed to parse XML. It's very light-weight (well, it used to be; it's a while since I've done XML stuff) and does the job.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With