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

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

android - CoordinatorLayout, FAB and container layout conflict -