title: Using getNodeSet on XMLNodeSet (XML package)
body: <p>I have trouble using the R XML package for a specific application I have in mind. Consider the following example document. I am interested in getting the information in b inside the first a node. But the nature of my problem (application) is so that I first <strong>need</strong> to identify all the a nodes in the document and then subset this nodeset to get the first a node and then get the b node. The first step is easy:</p>
  
  <pre><code>    doc &lt;- "
      &lt;div&gt;&lt;/div&gt;
      &lt;a id='1'&gt;&lt;b id='3'&gt;text1&lt;/b&gt;&lt;/a&gt;
      &lt;a id='2'&gt;&lt;b id='4'&gt;text2&lt;/b&gt;&lt;/a&gt;
      "
      parsed &lt;- htmlParse(doc)
  
      step1 &lt;- getNodeSet(parsed, "//a")
  
      &gt; step1
  
      [[1]]
  
      &lt;a id="1"&gt;
  
        &lt;b id="3"&gt;text1&lt;/b&gt;
  
      &lt;/a&gt; 
  
  
      [[2]]
  
      &lt;a id="2"&gt;
  
        &lt;b id="4"&gt;text2&lt;/b&gt;
  
      &lt;/a&gt; 
  
  
      attr(,"class")
  
      [1] "XMLNodeSet"
  </code></pre>
  
  <p>This yields the expected results. The next step in my application is to extract the b nodes from the first a node. If I use getNodeSet on step1[[1]], I get the b nodes from both nodes in the step1 nodeset.</p>
  
  <pre><code>    step2 &lt;- getNodeSet(step1[[1]], "//b")
      step2
  
      [[1]]
      &lt;b id="3"&gt;text1&lt;/b&gt; 
  
      [[2]]
      &lt;b id="4"&gt;text2&lt;/b&gt; 
  
      attr(,"class")
      [1] "XMLNodeSet"
  </code></pre>
  
  <p>I figured out that I could use the XPath "b" to get the information in this example, but ultimately I need "//b" to work here. The way I understand the XML package works, I don't think this behaviour is a bug, but a consequence of the reference of the C-level representation of this document. Is there a way I can achieve this "two-step" process by any way? I essentially want step[[1]] to work like a fresh document.</p>