title: Parsing HTML elements by id and class with XML package
body: <p>Is it possible to extract elements from an <code>HTMLInternalDocument</code> object by their <code>id</code> and <code>class</code> information?  For instance lets take a document:</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;
      &lt;title&gt;R XML test&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;div id="obj1"&gt;
      &lt;p id="txt1"&gt;quidquid&lt;/p&gt;
      &lt;p id="txt2"&gt;Latine dictum&lt;/p&gt;
  &lt;/div&gt;
  &lt;div class="mystuff"&gt;
      &lt;p&gt;sit altum&lt;/p&gt;
      &lt;p&gt;videtur&lt;/p&gt;
  &lt;/div&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>And read into R as follows:</p>
  
  <pre><code>require(XML)
  file &lt;- "C:/filepath/index.html"
  datain &lt;- htmlTreeParse(readLines(file), useInternalNodes = TRUE)
  </code></pre>
  
  <p>I'd like to extract the content of elements <code>id='txt2'</code> and <code>class='mystuff'</code>.</p>
  
  <p>I've tried various methods without success, and they all seem to iterate down the tree which is painfully laborious.  Is there a shortcut method using class/id?  I have an idea it might involve using first <code>getNodeSet</code> followed by some apply method (e.g. <code>xmlApply</code> &amp; <code>xmlAttrs</code>), but nothing I've tried works. Grateful for any pointers.</p>