What's the most commonly used XML library for C ++?

I went through several libraries via a quick google search. What's the most commonly used XML implementation for C ++?

I am planning to use XML as a tool to customize the program. I liked XML because I will be using its tree structure. If you think you have a better solution for this, feel free to talk about it. I want something light and simple. Is there too much XML?

Edit: cross platform would be preferred, but to answer the question, I'm programming this in Linux.

+2


source to share


6 answers


I would recommend not using XML.

I know this is a matter of opinion, but XML really clutters up information with a lot of tags. Also, even though it is human readable, the clutter actually makes it difficult to read (and I say this from experience since we have 134 XML configuration files at the moment ...). It is also quite difficult to read due to the combination of attributes and text. You never know which one you need.



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

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

+2


source


See if TinyXML helps



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

+7


source


There are several options:

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

      

I like expat. But this is a completely personal opinion.
I use it because it is small and it was easy to write a C ++ wrapper for.

Xerces is like a full sized XML parser with all the whistles. But, therefore, it is somewhat more difficult to use.

+3


source


Not exactly the question you asked, but there are two main aspects of XML parsers: SAX and DOM.

SAX parsers are event driven parsers. Since the parser sees various elements with the XML document (node, properties, etc.), the parser calls the specific function or method that you define.

DOM parsers, on the other hand, parse the entire XML document and return a tree structure that represents the entire document. Then your code can filter through the structure in whatever order it sees.

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

+1


source


I highly recommend pugixml

"pugixml is a C ++ XML processing library that consists of a DOM-like interface with rich traversal / modification capabilities, an extremely fast XML parser that creates a DOM tree from an XML file / buffer, and an XPath 1.0 implementation for complex data-driven trees. Full Unicode support is also available with Unicode interface options and conversions between different Unicode encodings.

I have tested several XML parsers, including several commercial ones, before choosing and using pugixml in a commercial product.

pugixml was not only the fastest (sometimes several times faster) parser, but also had the most mature and friendly API. I highly recommend it. This is a very stable product! I started using it since 0.8. Now it's 1.7.

A great bonus in this parser is the XPath 1.0 implementation! For any more complex queries the XPath tree is a function sent by God!

A DOM-like interface with rich traversal / modification capabilities is extremely useful for solving "heavy" real life XML files.

It is a small and fast parser. It's a good choice for an iOS or Android app if you don't mind linking C ++ code.

I have tested TinyXML as well. Not only was it slower, but it had problems with my XML files.

Tests say a lot: http://pugixml.org/benchmark.html

0


source


The XML libraries I have used and are still using are as follows:

If you don't need to use XML, I would suggest not.

I would also avoid modeling what you read / write as C ++ classes unless you are using a code generator.

I would also look at using a "schema for code" read / write, although make sure the license matches what you are doing.

0


source







All Articles