I followed this link http://www.technical-recipes.com/2014/using-boostproperty_tree/ to parse the xml. But how can I read the entire xml without the specifying a particular key? I tried the below code but it is unable to process it and I am getting the error as No such node.
Code:
const std::string XML_PATH1 = "./test1.xml";
#define ROOTTAG "roottag"
boost::property_tree::ptree pt1;
boost::property_tree::read_xml( XML_PATH1, pt1);
BOOST_FOREACH(boost::property_tree::ptree::value_type & node, pt1.get_child(ROOTTAG))
{
std::string tagname = node.first;
tagname += ".";
boost::property_tree::ptree subtree = node.second;
BOOST_FOREACH( boost::property_tree::ptree::value_type & v, subtree.get_child(node.first.data()))
{
//does not enter here
tagname += v.first.data();
tagname += ".";
xmlmap[tagname] = tagvalue;
}
}
What has to be specified in the second loop instead of node.first.data()
?
BOOST_FOREACH( boost::property_tree::ptree::value_type & v, subtree.get_child(node.first.data()))
Please note that I have to use BOOST_FOREACH
itself and use the same method.
I referred many websites but could not find how to read entire xml without specifying a particular key.
Also, how to read multi-level xml using the above method?