tags:

views:

234

answers:

5

I saw a few libraries through a quick Google search. What's generally the most commonly used XML implementation for C++?

I'm planning on using XML as a means for program configuration. I liked XML because I'll be making use of its tree-like structure. If you think you have a more suitable solution for this, feel free to mention it. I want something lightweight and simple. Maybe XML is too much?

Edit: Cross-platform would be preferable, but to answer a question, I'm programming this in Linux.

+3  A: 

There are several out there:

Xercers   Big    http://xerces.apache.org/xerces-c/  
expat     small  http://expat.sourceforge.net/

I like expat. But that's a totally personal opinion.
I use it because it is small and it was simple to write a C++ wrapper for.

Xerces is like the full blown XML parser with all the knobs a whistles. But consequently it is slightly more complex to use.

Martin York
Can expat write XML files?
Scott
Expat is purely a parser - it reads the input and calls callbacks for particular kinds of syntax (element, attribute etc). You register the callbacks for the events you're interested in. It's at a similar level to SAX, but doesn't follow SAX conventions. There's no output support, but output is a simpler job anyway - though there are obvious character set/encoding issues.
Steve314
A: 

Which os platform do you intend to use?

//Buzzz

Buzzzz
Linux, but cross-platform would be preferable.
Scott
This really shouldn't matter unless you plan on recommending AsmXML: http://mkerbiquet.free.fr/asm-xml/
Chris Lutz
Well if you are on a windows platform you can use MSXML which I guess isn't available under linux.
Buzzzz
+7  A: 

See if TinyXML helps you

TinyXML is a simple, small, C++ XML parser that can be easily integrating into other programs.

sat
There is a more C++ friendly version too, TiCPP. http://code.google.com/p/ticpp/
Rob
+1  A: 

Not quite the question you asked, but there are two major flavors of XML parsers, SAX and DOM.

SAX parsers are event driven parsers. As the parser sees various elements with the XML document (node, properties, etc.), the parser calls some function or method that you have defined.

DOM parsers on the other hand parse the entire XML document and return a tree structure that represents the entire document. Your code can then poke through the structure in any order it sees.

SAX parsers are more memory efficient because they do not need to represent the entire document in memory. DOM parsers are easier to work with because you are not limited to processing the document in a linear fashion.

R Samuel Klatchko
Worthwhile note - Expat is SAX-like in this scheme, but is not SAX. SAX was originally a Java library, but it's API became the model for a kind of multi-language standard. Expat was always C, and (I think) predates SAX.
Steve314
+1  A: 

I would recommend not using XML.

I know this is a matter of opinion but XML really clutters the information with a lot of tags. Also, even though it is human-readable, the clutter actually hampers readability (and I say it from experience since we have some 134 XML configuration files at the moment...). Furthermore, it is quite difficult to read because of the mix between attributes and plain-text. You never know which one you are going to need.

I would recommend using JSON, if you want a language that already has well-defined parsers.

For parsing, a simple look at json.org and you have a long list of C++ libraries.

Matthieu M.
Use or not use xml much depends on the application and not the taste of the programmer.
lsalamon
If the author wanted to know answer on **your** question (Should I use XML?) he would have asked this question not the one he asked. -1
Piotr Dobrogost
Piotr, actually I did leave the question open for an answer like this. Read it again. :)
Scott
Incidentally, I think I'm going to use JSON, Matthieu. I'm embedding Javascript, so JSON really makes sense for configuration.
Scott
Though XML may have originally been designed as Human readable its not really (But the XML readers which are ubiqitos make it trivial to read). But that is not why XML is usefull. It because of its machine readability that it is usfull and the fact that if hard pressed you can go into and hack the XML if pushed and be pretty secure you have not invalidated the whole file. Thes same can not be said for Jason which is definately not Human readable or hackable without major concentration.
Martin York