xml parser for c++

Started by
10 comments, last by Lode 15 years, 4 months ago
I've been searching around for good xml libraries for C++, but I can't seem to find any that are really good and that expose a simple, C++ idiomatic interface. What I need is basically a simple and fast XML standard conforming parser that returns a tree of xml nodes, preferably automatically memory managed by proper destructors or use of smart pointers or pointer containers. No need for DTD validation, but there should be validation that the input is in well-formed xml. libxml2 doesn't meet these needs, as it is in C, not C++, and the C++ binding requires an awful lot of other libraries to run, which is pretty annoying when you switch work stations often and have to install all these libraries and set up paths anew. Haven't really heard much about any of the other libraries. Is Xerxes a good library? Are there other alternatives? Are there good open source alternatives that nearly meet the requirements above, that are well-written enough that it's feasible to adapt them to own needs? What would you recommend? The usage will mostly be for config files, but I'm also thinking a bit ahead that learning a good xml parsing library for C++ can be useful for all sorts of future application areas where xml is used.
Advertisement
My two suggestions would be Xerces or Qt. Qt is a huge library, but it has QtXml, which is kind of nice. But, Qt is dual-licensed, so either commercial, with a steep cost, or the GPL virus.

I've also used Expat before. Expat is nice, but the one problem I had with it, is that it's all C code. I wound up having to manually write a C++ wrapper around it.
If you want a simple, C++ style XML parser, I recommend ticpp (http://code.google.com/p/ticpp/). I commonly use Qt's XML parser, because I'm often already using Qt for my gui. However, for other projects w/o a gui, where I need a nice and simple XML parser, I use ticpp. It's small, and C++-centric. It doesn't do DTD validation, but will ensure that the XML constitutes a valid document.

Cheers,
Rob
What about TinyXml?
Quote:Original post by rufus74
What about TinyXml?


From the ticpp website:

"'TiCPP' is short for the official name TinyXML++. It is a completely new interface to TinyXML (http://www.grinninglizard.com/tinyxml/) that uses MANY of the C++ strengths. Templates, exceptions, and much better error handling. It is also fully documented in doxygen. It is really cool because this version let's you interface tiny the exact same way as before or you can choose to use the new 'ticpp' classes. All you need to do is define TIXML_USE_TICPP."

As you can see, TiCPP is just a more C++ idiomatic wrapper for TinyXml (which, I agree, is a great library by the way).

Cheers,
Rob
I've never used this one, but it looks cool.

Clicky. Click on the tab "All Downloads", and the first item in the bar below it is an XML parser library. It's just one .h and one .cpp, with no dependencies except stdio or something like that.
+1 for TinyXml. I haven't tried TiCPP yet.
You could also look at RapidXML.

I haven't used it but I like the cut of its jib.

At one point I looked at http://pocoproject.org/ for XML, but TinyXML won.
+1 for TinyXML.

This topic is closed to new replies.

Advertisement