title: How to iterate over XML structure in boost::property_tree
body: <p>I have an XML structure along the lines of:</p>
  
  <pre><code>&lt;root&gt;
   &lt;SomeElement&gt;
    &lt;AnotherElement&gt;
     &lt;ElementIWant x="1" y="1"/&gt;
    &lt;/AnotherElement&gt;
   &lt;/SomeElement&gt;
   &lt;SomeElement&gt;
    &lt;AnotherElement&gt;
     &lt;ElementIWant x="1" y="1"/&gt;
     &lt;ElementIWant x="2" y="1"/&gt;
     &lt;ElementIWant x="3" y="1"/&gt;
    &lt;/AnotherElement&gt;
   &lt;/SomeElement&gt;
  &lt;/root&gt;
  </code></pre>
  
  <p>Which is being read into a <code>boost::property_tree</code>, There are <em>1..Many</em> <code>&lt;SomeElement&gt;</code>s, and then at an arbitrary depth within that element there could be <em>1..Many</em> <code>&lt;ElementIWant&gt;</code>s </p>
  
  <p><strong>Is there a way to iterate over the <code>&lt;ElementIWant&gt;</code> directly (in a single loop) in the order that they appear in the doc?</strong> </p>
  
  <p>I have looked at equal_range </p>
  
  <pre><code>void iterateOverPoints()
  {
       const char* test = 
       "&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;&lt;root&gt;"
        "&lt;SomeElement&gt;"
         "&lt;AnotherElement&gt;"
          "&lt;ElementIWant x=\"1\" y=\"1\"/&gt;"
         "&lt;/AnotherElement&gt;"
        "&lt;/SomeElement&gt;"
        "&lt;SomeElement&gt;"
         "&lt;AnotherElement&gt;"
          "&lt;ElementIWant x=\"1\" y=\"1\"/&gt;"
          "&lt;ElementIWant x=\"2\" y=\"1\"/&gt;"
          "&lt;ElementIWant x=\"3\" y=\"1\"/&gt;"
         "&lt;/AnotherElement&gt;"
        "&lt;/SomeElement&gt;"
      "&lt;/root&gt;";
  
      boost::property_tree::ptree message;
      std::istringstream toParse(test); 
      boost::property_tree::read_xml(toParse,result_tree);
  
      //Now we need to locate the point elements and set the x/y accordingly.
      std::pair&lt; boost::property_tree::ptree::const_assoc_iterator,
                 boost::property_tree::ptree::const_assoc_iterator &gt; result =
           message.equal_range("ElementIWant");
  
      for( boost::property_tree::ptree::const_assoc_iterator it = result.first; 
             it != result.second; ++it )
      {
          std::cout  &lt;&lt; it-&gt;first &lt;&lt; " : ";
          const boost::property_tree::ptree&amp; x = it-&gt;second.get_child( "&lt;xmlattr&gt;.x" );
          const boost::property_tree::ptree&amp; y = it-&gt;second.get_child( "&lt;xmlattr&gt;.y" );
          std::cout &lt;&lt; x.get_value&lt;int&gt;() &lt;&lt; "," &lt;&lt; y.get_value&lt;int&gt;() &lt;&lt; "\n";
      }
  
      return;
  }
  </code></pre>
  
  <p>However it seems to fail to return nodes (Which I suspect is because equal_range works at the level of the tree node supplied) Which brings me to the question above...</p>