You control it, and it reads only once:
//
// All that is required to read an xml file into the tree
//
std::ifstream in("region.xml");
boost::property_tree::ptree result_tree;
boost::property_tree::read_xml(in,result_tree);
Include the correct header and read ini, json or xml files into the tree using the corresponding read_XXX method.
You then use a "path" to access elements from the tree, or you can iterate over subtrees
BOOST_FOREACH(boost::property_tree::ptree::value_type &v,result_tree.get_child("gpx.rte"))
{
if( v.first == "rtept" ) //current node/element name
{
boost::property_tree::ptree subtree = v.second ;
//A path to the element is required to access the value
const int lat = sub_tree.get<double>( "<xmlattr>.lat")*10000.0;
const int lon = sub_tree.get<double>( "<xmlattr>.lon")*10000.0;
}
}
or direct access via a path:
// Here is simplistic access of the data, again rewritten for flexibility and
// exception safety in real code (nodes shortened too)
const int distVal =
result_tree.get<int>
( "Envelope.Body.MatrixResponse.Matrix.Route.<xmlattr>.distance")/1000;