title: R XML + XPath - getNodeSet with multiple conditions
body: <p>I'm new to XPath - please go easy on me.</p>
  
  <p>Having trouble extracting XPath on my target pages for elements that don't have a lot of  structure.</p>
  
  <p>The data set is NJ school <a href="http://education.state.nj.us/rc/rc11/nav.php?c=0" rel="nofollow noreferrer">report cards</a>.  Individual report cards look like <a href="http://education.state.nj.us/rc/rc11/rcreport.php?c=01;d=0110;s=100" rel="nofollow noreferrer">this</a></p>
  
  <p>I've figured out how to pull out tables that have a <code>summary</code> tag:</p>
  
  <pre><code>url &lt;- paste("http://education.state.nj.us/rc/rc11/rcreport.php?c=",
    all_sch[i,1],";d=",all_sch[i,2],";s=",all_sch[i,3],sep = '')
  doc = htmlParse(url)
  admin_salaries = getNodeSet(doc, '//table[@summary="Administrative Salaries and Benefits"]')
  </code></pre>
  
  <p>but am having trouble where there isn't a lot of extra identifying information to work off of.</p>
  
  <p>For instance, the table that has school name and district looks like this:</p>
  
  <pre><code>        &lt;table cellpadding="0" cellspacing="0"&gt;
            &lt;tr&gt;
              &lt;td&gt;&lt;strong&gt;SCHOOL:&lt;/strong&gt;&lt;/td&gt;
              &lt;td&gt;&amp;nbsp;New Jersey Ave&lt;/td&gt;
            &lt;/tr&gt;
            &lt;tr&gt;
              &lt;td&gt;&lt;strong&gt;COUNTY:&lt;/strong&gt;&lt;/td&gt;
              &lt;td&gt;&amp;nbsp;Atlantic&lt;/td&gt;
            &lt;/tr&gt;
            &lt;tr&gt;
              &lt;td&gt;&lt;strong&gt;DISTRICT:&lt;/strong&gt;&lt;/td&gt;
              &lt;td&gt;&amp;nbsp;Atlantic City&lt;/td&gt;
            &lt;/tr&gt;
          &lt;/table&gt;
  </code></pre>
  
  <p>My strategy here was 'find nodes that are tables and have the text <code>COUNTY</code></p>
  
  <p><a href="https://stackoverflow.com/questions/2599198/select-on-multiple-criteria-with-xpath">Reading</a> as much as I can about XPath, I'm trying this:</p>
  
  <pre><code>names = getNodeSet(doc,'//table and //*[contains(text(),"COUNTY")]')
  </code></pre>
  
  <p>But instead of returning back the table node, it gives me a boolean <code>TRUE</code> value.</p>
  
  <p>So, the question is: <strong>How can I use XPath to find tables that have the text COUNTY and SCHOOL?</strong></p>
  
  <p>I've tried a lot of other strategies to little avail.  One approach suggested by others was simply to pull out every table data cell using something like this:</p>
  
  <pre><code>xpathApply( htmlTreeParse(url, useInt=T), "//td", function(x) xmlValue(x))
  </code></pre>
  
  <p>But the templates aren't consistent for missing data - incomplete reports have pretty different structure, and elements aren't in the same position across the 2,000+ pages.</p>
  
  <p>Any help is greatly appreciated!</p>