I want to parse XML and change the contents of the XML
Which one should I choose? boost::spirit or boost::serialization

Thanks a lot

Recommended Answers

All 6 Replies

Boost.Spirit should be used. Boost.Spirit is the library that allows you to create a grammar and do parsing / generation of XML data.

The purpose of Boost.Serialization is very different, it is true that it can interact with XML to do the serialiation / unserialization, but it isn't a parsing library, rather a library that uses some XML generation / parsing. I don't know if it uses Boost.Spirit for generating / parsing its XML data.

Thanks, I search for several examples about parsing XML with serialization
Some of the posts suggest serialization and some of them suggest spirit
I found that spirit is very flexible when you need to parse something, you
could create your own parsing machine by spirit.

Last day I was studying boost::filesystem3, it is very intuitive, neat and flexible.
But I don't know the prices of boost::filesystem3, there are no such thing like
"effective XX" to study about. What should we care when using filesystem3?


You weirdly seem to be comparing apples and oranges.

If you need to do serialization (or marschalling), then Boost.Serialization is a great tool (not necessarily the most appropriate at all times, but a very good one). And, of course, one of the main, universal, file-format used by boost-serialization is XML, but I doubt that you can easily use it to load XML data that wasn't originally generated by the Boost.Serialization library in the first place (i.e. it is not a generic parser of XML).

If you need to do parsing, then Boost.Spirit is quite an awesome library for that (and the DSEL is wonderful). Btw, parsing XML (or at least, a basic form of it) is the main tutorial on the official site of Boost.Spirit.

If you need to manipulate files and directories, then Boost.File-System is a great tool.

These three tasks are completely different and orthogonal to each other. The choice depends on the task at hand, period.

As for boost filesystem3, I am not familiar with it too much (I never needed to do much file system operations in C++, at least, recently).

You weirdly seem to be comparing apples and oranges.

Sorry, I should place the problem of boost::filesystem3 on another thread
I would choose boost::spirit to parse XML and use filesystem3 to do some
jobs about file manipulation.

Thanks for your advices.

Have a look at RapidXML, perhaps? Extremely good as long as DTD support is not required.

From the Boost Property Tree documentation:
"The XML format is an industry standard for storing information in textual form. Unfortunately, there is no XML parser in Boost as of the time of this writing. The library therefore contains the fast and tiny RapidXML parser (currently in version 1.13) to provide XML parsing support. RapidXML does not fully support the XML standard; it is not capable of parsing DTDs and therefore cannot do full entity substitution."

There was a discussion about this in lib.boost.devel and the consensus there was to use RapidXML.

Thanks, I would study RapidXML and boost::spirit,
although boost:spirit is not designed for XML,
it is pretty attractive.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.