title: What's the most efficient way to do recursive XPath queries using libxml2?
body: <p>I've written a C++ wrapper function for libxml2 that makes it easy for me to do queries on an XML document:</p>
  
  <pre><code>bool XPathQuery(
      const std::string&amp; doc,
      const std::string&amp; query,
      XPathResults&amp; results); 
  </code></pre>
  
  <p>But I have a problem: I need to be able to do another XPath query on the results of my first query.</p>
  
  <p>Currently I do this by storing the entire subdocument in my XPathResult object, and then I pass XPathResult.subdoc into the XPathQuery function. This is awfully inefficient.</p>
  
  <p>So I'm wondering ... does libxml2 provide anything that would make it easy to store the context of an xpath query (a reference to a node, perhaps?) and then perform another query using that reference as the xpath root?</p>