Boost has a tutorial on how to load XML from a file. How do I feed it with a string that I either create in code or receive from a user (e.g. with cin
)?
Heres some code that works for me...
// Create an empty property tree object
ptree xmlTree;
// Read the XML config string into the property tree. Catch any exception
try {
stringstream ss; ss << xmlConfigString;
read_xml(ss, xmlTree);
}
catch (xml_parser_error &e) {
LOGERROR ("Failed to read config xml " << e.what());
}
catch (...) {
LOGERROR ("Failed to read config xml with unknown error");
}
Wrap the string in an istringstream
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With