ProAnswers.org

Boost to read and write xml files?

Is there any good way or simple way using boost to read and write xml files?

I can’t seem to find any simple sample to read xml files using boost? (can you point me some simple sample that use boost for reading and writing xml files)

You should Try pugixml Light-weight, simple and fast XML parser for C++

The nicest thing about pugixml is the [b]XPath[/b] support, which TinyXML and RapidXML lack.



Quoting RapidXML's author "I would like to thank Arseny Kapoulkine for his work on pugixml, which was an inspiration for this project" and "5% - 30% faster than pugixml, the fastest XML parser I know of" He had tested against version 0.3 of pugixml, which has reached recently version 0.42.



Here is an excerpt from pugixml documentation:



The main features are:




	low memory consumption and fragmentation (the win over pugxml is ~1.3 times, TinyXML - ~2.5 times, Xerces (DOM) - ~4.3 times 1). Exact numbers can be seen in Comparison with existing parsers section.

	extremely high parsing speed (the win over pugxml is ~6 times, TinyXML - ~10 times, Xerces-DOM - ~17.6 times 1

	extremely high parsing speed (well, I'm repeating myself, but it's so fast, that it outperforms Expat by 2.8 times on test XML) 2

	more or less standard-conformant (it will parse any standard-compliant file correctly, with the exception of DTD related issues)

	pretty much error-ignorant (it will not choke on something like You & Me, like expat will; it will parse files with data in wrong encoding; and so on)

	clean interface (a heavily refactored pugxml's one)

	more or less Unicode-aware (actually, it assumes UTF-8 encoding of the input data, though it will readily work with ANSI - no UTF-16 for now (see Future work), with helper conversion functions (UTF-8  UTF-16/32 (whatever is the default for std::wstring & wchar_t))

	fully standard compliant C++ code (approved by Comeau strict mode); the library is multiplatform (see reference for platforms list)

	high flexibility. You can control many aspects of file parsing and DOM tree building via parsing options.