12

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).

John Bartholomew
  • 6,428
  • 1
  • 30
  • 39

3 Answers3

10

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.

sbi
  • 219,715
  • 46
  • 258
  • 445
  • I must admit I didn't give expat the attention it deserved. Do you use it with a C++ wrapper? If so, which one? – John Bartholomew Jan 13 '11 at 19:52
  • @John: It took me a while to remember, but when I did this, I used this one: http://beta.codeproject.com/KB/XML/expatimpl.aspx. But that was only a very thin wrapper and it is now seriously outdated. – sbi Jan 13 '11 at 23:40
  • Alright. Looks like expat is reasonable, even if I put my own C++ wrapper over it. – John Bartholomew Jan 13 '11 at 23:46
  • what about TinyXML and its C++ wrapper TinyXML++? –  Jan 14 '11 at 00:22
  • @Monomer: I don't know. The only parser I ever used (after looking at a few of them many years ago) was expat. Maybe TinyXML is as good or even better. I wouldn't know. – sbi Jan 14 '11 at 08:46
6

you can try https://github.com/thinlizzy/die-xml . it seems to be very small and easy to use

this is a recently made C++0x XML SAX parser open source and the author is willing feedbacks

it parses an input stream and generates events on callbacks compatible to std::function

the stack machine uses finite automata as a backend and some events (start tag and text nodes) use iterators in order to minimize buffering, making it pretty lightweight

Carlo Wood
  • 5,648
  • 2
  • 35
  • 47
thinlizzy
  • 668
  • 8
  • 13
-3

PugiXML and RapidXML do not have DOM conforming interfaces.. those API came with severe limitations on functionalities and conformance. You might want to investigate VTD-XML that is signifiantly more advanced than either DOM or SAX/Pull

vtd-xml-author
  • 3,319
  • 4
  • 22
  • 30