c++ How to read XML using boost xml parser and store in map
<p>As an example I am using the XML file listed here:</p>

<pre><code>https://msdn.microsoft.com/en-us/library/ms256129(v=vs.110).aspx
</code></pre>

<p>The XML File:</p>

<pre><code>&lt;?xml version="1.0"?&gt;
&lt;purchaseOrder xmlns="http://tempuri.org/po.xsd" orderDate="1999-10-20"&gt;
    &lt;shipTo country="US"&gt;
        &lt;name&gt;Alice Smith&lt;/name&gt;
        &lt;street&gt;123 Maple Street&lt;/street&gt;
        &lt;city&gt;Mill Valley&lt;/city&gt;
        &lt;state&gt;CA&lt;/state&gt;
        &lt;zip&gt;90952&lt;/zip&gt;
    &lt;/shipTo&gt;
    &lt;billTo country="US"&gt;
        &lt;name&gt;Robert Smith&lt;/name&gt;
        &lt;street&gt;8 Oak Avenue&lt;/street&gt;
        &lt;city&gt;Old Town&lt;/city&gt;
        &lt;state&gt;PA&lt;/state&gt;
        &lt;zip&gt;95819&lt;/zip&gt;
    &lt;/billTo&gt;
    &lt;comment&gt;Hurry, my lawn is going wild!&lt;/comment&gt;
    &lt;items&gt;
        &lt;item partNum="872-AA"&gt;
            &lt;productName&gt;Lawnmower&lt;/productName&gt;
            &lt;quantity&gt;1&lt;/quantity&gt;
            &lt;Price&gt;
                &lt;USPrice&gt;148.95&lt;/USPrice&gt;
                &lt;UKPrice&gt;150.02&lt;/UKPrice&gt;
            &lt;/Price&gt;
            &lt;comment&gt;Confirm this is electric&lt;/comment&gt;
        &lt;/item&gt;
        &lt;item partNum="926-AA"&gt;
            &lt;productName&gt;Baby Monitor&lt;/productName&gt;
            &lt;quantity&gt;1&lt;/quantity&gt;
            &lt;Price&gt;
                &lt;USPrice&gt;39.95&lt;/USPrice&gt;
                &lt;UKPrice&gt;37.67&lt;/UKPrice&gt;
            &lt;/Price&gt;
            &lt;USPrice&gt;39.98&lt;/USPrice&gt;
            &lt;shipDate&gt;1999-05-21&lt;/shipDate&gt;
        &lt;/item&gt;
    &lt;/items&gt;
&lt;/purchaseOrder&gt;
</code></pre>

<p>Currently I am using the following code but using that I am able to read only one child node that is purchaseOrder.shipTo country only. how to read till tag USPrice? Does boost xml parser support 4 level tag value parsing?</p>

<pre><code>const std::string XML_PATH1 = "./test1.xml";
#define ROOTTAG  "purchaseOrder"
    boost::property_tree::ptree pt;
    boost::property_tree::read_xml( XML_PATH1, pt);
    BOOST_FOREACH(boost::property_tree::ptree::value_type &amp; v, pt.get_child(ROOTTAG)){
        xmlmap[v.first.data()] = v.second.data();
    }
</code></pre>

<p>I want to read and store as follows in the <code>xmlmap &lt;string, string&gt;</code>.</p>

<pre><code>map key = items.item partNum.USPrice
map value = 39.98 (post converting to string)
</code></pre>

<p><strong>Update:</strong></p>

<p>I tried the following but it is giving me compilation error as</p>

<pre><code>error: ‘boost::property_tree::ptree’ has no member named ‘second’
                         boost::property_tree::ptree lt = subtree.second;
</code></pre>

<p><strong>Code:</strong></p>

<pre><code>const std::string XML_PATH1 = "./test1.xml";
#define ROOTTAG  "purchaseOrder"
boost::property_tree::ptree pt1;
boost::property_tree::read_xml( XML_PATH1, pt1);
BOOST_FOREACH(boost::property_tree::ptree::value_type &amp; node, pt1.get_child(ROOTTAG))
{
    std::string tagname = node.first;
    tagname += ".";
    boost::property_tree::ptree subtree = node.second;
    BOOST_FOREACH( boost::property_tree::ptree::value_type &amp; v, subtree.get_child(node.first.data()))
    {
        boost::property_tree::ptree lt = subtree.second;
        tagname += v.first.data();
        tagname += ".";
        BOOST_FOREACH( boost::property_tree::ptree::value_type &amp; vt, lt.get_child(v.first.data()))
            {
                std::string name1 = vt.first.data();
                tagname += name1;
                if(name1 != "&lt;xmlattr&gt;") {
                    std::string tagvalue = lt.get&lt;std::string&gt;(name1);
                    tagname += name1;
                    xmlmap[tagname] = tagvalue;
                    }
             }
      }
}
</code></pre>