Skip to content

Instantly share code, notes, and snippets.

@sh0seo
Created February 10, 2016 15:03
Show Gist options
  • Save sh0seo/c45b524a386900455634 to your computer and use it in GitHub Desktop.
Save sh0seo/c45b524a386900455634 to your computer and use it in GitHub Desktop.
#include <string>
#include <boost/property_tree/xml_parser.hpp>
#include <boost/property_tree/ptree.hpp>
#include <boost/foreach.hpp>
const std::string XML_PATH1 = "./test1.xml";
int main()
{
boost::property_tree::ptree pt1;
boost::property_tree::read_xml( XML_PATH1, pt1 );
// Traverse property tree example
BOOST_FOREACH( boost::property_tree::ptree::value_type const& node, pt1.get_child( "purchaseOrder.items" ) )
{
boost::property_tree::ptree subtree = node.second;
if( node.first == "item" )
{
BOOST_FOREACH( boost::property_tree::ptree::value_type const& v, subtree.get_child( "" ) )
{
std::string label = v.first;
if ( label != "<xmlattr>" )
{
std::string value = subtree.get<std::string>( label );
std::cout << label << ": " << value << std::endl;
}
}
std::cout << std::endl;
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment