Created
February 10, 2016 15:03
-
-
Save sh0seo/c45b524a386900455634 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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