What is the common denominator XML library across Linux and Windows for parsing XML in C or C++?
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 开发者_如何学JAVAdistros, libxml2 seems to be fairly common, but is there a more common xml library?
Xerces and Expat are very common as well.
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.
- 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.
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.
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).
Other Similar but not exact duplicate questions:
- A lightweight XML parser efficient for large files?
- Ways to parse XML in C++ (Win32)
- What's the most commonly used XML library for C++?
- Alternatives to expat for stream-oriented XML parsing in C++
精彩评论