Boost uses RapidXML as described in chapter XML Parser of page How to Populate a Property Tree:
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.
Please also refer to the XML boost tutorial.
As the OP wants a "simple way to use boost to read and write xml files", I provide below a very basic example:
<main>
<owner>Matt</owner>
<cats>
<cat>Scarface Max</cat>
<cat>Moose</cat>
<cat>Snowball</cat>
<cat>Powerball</cat>
<cat>Miss Pudge</cat>
<cat>Needlenose</cat>
<cat>Sweety Pie</cat>
<cat>Peacey</cat>
<cat>Funnyface</cat>
</cats>
</main>
(cat names are from Matt Mahoney's homepage)
The corresponding structure in C++:
struct Catowner
{
std::string owner;
std::set<std::string> cats;
};
read_xml()
usage:
#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/xml_parser.hpp>
Catowner load(const std::string &file)
{
boost::property_tree::ptree pt;
read_xml(file, pt);
Catowner co;
co.owner = pt.get<std::string>("main.owner");
BOOST_FOREACH(
boost::property_tree::ptree::value_type &v,
pt.get_child("main.cats"))
co.cats.insert(v.second.data());
return co;
}
write_xml()
usage:
void save(const Catowner &co, const std::string &file)
{
boost::property_tree::ptree pt;
pt.put("main.owner", co.owner);
BOOST_FOREACH(
const std::string &name, co.cats)
pt.add("main.cats.cat", name);
write_xml(file, pt);
}