title: iterate through boost property tree
body: <p>I'm iterating over an XML document using boost property
  tree and storing the results in a struct. The issue I have is that I can
  only get to the first "item" nodes and can't access the second "item"
  nodes. I was hoping someone would point out where I've made a mistake.</p>
  
  <p>My program output looks like this (you can see items are missing.. there
  is no cookie2, candy2 or chocolate2 items shown):</p>
  
  <pre><code>jar : snAcks
  snack : coOkie
  item : cooKie1
  snack : canDy
  item : caNdy1
  snack : cHocolate
  item : choColate1
  </code></pre>
  
  <p>Here's the xml file:</p>
  
  <pre><code>&lt;root&gt;
      &lt;jar name="snAcks"&gt;
          &lt;snack name="coOkie"&gt;
             &lt;item name="cooKie1"&gt;&lt;/item&gt;
             &lt;item name="cookIe2"&gt;&lt;/item&gt;
          &lt;/snack&gt;
          &lt;snack name="canDy"&gt;
             &lt;item name="caNdy1"&gt;&lt;/item&gt;
             &lt;item name="candY2"&gt;&lt;/item&gt;
          &lt;/snack&gt;
          &lt;snack name="cHocolate"&gt;
             &lt;item name="choColate1"&gt;&lt;/item&gt;
             &lt;item name="chocOlate2"&gt;&lt;/item&gt;
          &lt;/snack&gt;
      &lt;/jar&gt;
  &lt;/root&gt;
  </code></pre>
  
  <p>Here's the source code:</p>
  
  <pre><code>void parse_xml( boost::property_tree::iptree const&amp; pt )
  {
      BOOST_FOREACH( boost::property_tree::iptree::value_type const&amp; v, pt.get_child("root.jar") )
      {
          // Show jar
          if ( boost::iequals( v.first, "&lt;xmlattr&gt;" ) )
          {
              std::cout &lt;&lt; "jar : " &lt;&lt; v.second.get&lt;std::string&gt;("NaME") &lt;&lt; std::endl;
          }
  
          if ( boost::iequals( v.first, "snack" ) )
          {
              // Show snack
              std::cout &lt;&lt; "snack : " &lt;&lt; v.second.get&lt;std::string&gt;("&lt;xmlattr&gt;.name")  &lt;&lt; std::endl;
  
              try
              {
                  BOOST_FOREACH( boost::property_tree::iptree::value_type const&amp; val, v.second.get_child("item") )
                  {
                      if ( boost::iequals( val.first, "&lt;xmlattr&gt;" ) ) {
                          // Show item
                          std::cout &lt;&lt; "item : " &lt;&lt; val.second.get&lt;std::string&gt;("nAmE")  &lt;&lt; std::endl;
                      }
                  }
              }
  
              catch (boost::property_tree::ptree_bad_path&amp; e)
              {
                  // Show what caused exception
                  std::cout &lt;&lt; "Exception: " &lt;&lt; e.what() &lt;&lt; std::endl;
              }
          }
      }
  }
  </code></pre>
  
  <p>Thank you for taking time to read this. I think I've made a simple
  mistake, but cannot understand where.</p>