xml - C++ Boost loop through unknown ptree and list values of attributes -
i'd parse random xml files nodes containing specific attribute , retrive values of attribute. use case there many xml different nodes attribute retrieve known.
here example of file :
<node> <container> <object attribute="value" /> <object attribute="value" /> <container/> <supercontainer> <subcontainer> <otherobject attribute="value" /> <subcontainer/> <supercontainer/> </node>
this have using boost property_tree don't know in loop:
ptree pt; read_xml(xml_file, pt); boost_foreach(boost::property_tree::ptree::value_type &ele, pt) { //no idea }
ideas welcome.
thanks
ok, solved using following :
void recursemanifest(ptree &pt, int lvl) { (ptree::iterator current = pt.begin(); current != pt.end();) { try { std::cout << current->second.get<std::string>("<xmlattr>.attribute") << std::endl; } catch(const boost::property_tree::ptree_bad_path &err) { std::cerr << err.what() << std::endl; } assets = recursemanifest(current->second, lvl++); ++current; } }
Comments
Post a Comment