tags:

views:

125

answers:

6

I want to parse some XML in a C and C++ app. This app is deployed to Windows and Linux. What is an XML library that is likely to be installed on many Linux distributions and is readily available on Windows?

From my samples of Linux distros, libxml2 seems to be fairly common, but is there a more common xml library?

+6  A: 

Xerces and Expat are very common as well.

Eugen Constantin Dinca
Expat gets my vote.
anon
+2  A: 

I do not think you will find anything likely to be pre-installed in both systems. As you say, libxml2 is ubiquitous on Linux but not on Windows.

You will likely be installing something yourself on at least one of them.

libxml2 is quite portable though if you just want to ship it with your app. The design is actually based off the XML API in .NET.

Justin
RE: libxml2: Err.. more likely it's based off the W3C DOM, after which the .NET libraries are also patterned.
Billy ONeal
Well, I realize that Billy is getting up voted but read this:http://www.xmlsoft.org/xmlreader.html
Justin
@Justin: Okay, you found one class in libxml patterned after a .NET idiom. That doesn't mean that the core design of the library is taken from .NET. The core design of the .NET libraries are simply a port of the W3C DOM.
Billy ONeal
No one of sane mind would model anything after C#. C# always follows suit after something in C or C++.
Matt Joiner
@Billy. Of course, the W3C DOM is the root of both. I was not trying to start a religious war and apologize if you find my original answer an overstatement. Peace. @Matt. The idea of a a pull parser appeared first in .NET as acknowledged by the libxml folks. Facts are facts. In C language terms, I am afraid that some of your pointers clearly reference garbage (memory fault!).
Justin
+2  A: 
  • pugixml <-- Probably the simplest to use, but has few features.
  • rapidxml <-- Faster but even less feature rich than pugixml.
  • Xerces <-- Sort of the "standard" XML parser -- supports pretty much every XML standard out there, can parse/enforce DTDs, etc. Not particularly fast though.
  • TinyXML <-- Slow, not feature rich. But is tiny and easy to use.
Billy ONeal
+1  A: 

Qt is quite good at cross-platform development.If you don't mind the extra library(libqt4-core),I suggest you use Qt's xml module.DOM or SAX will get the job done.

schemacs
Qt is NOT a C++ library. It must be passed through a separate program first in order to generate the correct signals and slots code. (It has exception safety problems too but that's another issue)
Billy ONeal
Qt is a C++ library. The preprocessing is not required if you don't use the signal-slot functionality.
Philipp
You can just use the non-gui framework,i.e. the xml module only.As Phillipp said,,avoid the signal-slot mechanism.As with exception safety problem,I guess with Qt,you can only be better to handle it.
schemacs
+1  A: 

If you want a plain (SAX-like, stream-based) parser, then the answer is definitely Expat.

But you mentioned libxml2, then you are probably interested in a (convenient) Document Object Model produced by the parser (and also vice-versa: creating a DOM and writing it to an XML file, and similar usages).

For an easy-to-use, cross-platform library, give TinyXML a try. This library is small and just does the job and is ok for many XML parsing purposes by providing practice-oriented interfaces (which are similar to, but does not exactly resemble the DOM standard).

frunsi