title: Using XPath Contains against HTML in Java
body: <p>I'm scraping values from HTML pages using XPath inside of a java program to get to a specific tag and occasionally using regular expressions to clean up the data I receive.  </p>
  
  <p>After some research, I landed on HTML Cleaner ( <a href="http://htmlcleaner.sourceforge.net/" rel="noreferrer">http://htmlcleaner.sourceforge.net/</a> ) as the most reliable way to parse raw HTML into a good XML format. HTML Cleaner, however, only supports XPath 1.0 and I find myself needing functions like 'contains'. for instance, in this piece of XML:</p>
  
  <pre><code>&lt;div&gt;
    &lt;td id='1234 foo 5678'&gt;Hello&lt;/td&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>I would like to be able to get the text 'Hello' with the following XPath:</p>
  
  <pre><code>//div/td[contains(@id, 'foo')]/text()
  </code></pre>
  
  <p>Is there any way to get this functionality?  I have several ideas, but would prefer not to reinvent the wheel if I don't need to:</p>
  
  <ul>
  <li>If there is a way to call HTML Cleaner's evaluateXPath and return a TagNode (which I have not found), I can use an XML serializer on the returned TagNode and chain together XPaths to achieve the desired functionality.</li>
  <li>I could use HTML Cleaner to clean to XML, serialize it back to a string, and use that with another XPath library, but I can't find a good java XPath evaluator that works on a string.</li>
  <li>Using TagNode functions like getElementsByAttValue, I could essentially recreate XPath evaluation and insert in the contains functionality using String.contains</li>
  </ul>
  
  <p>Short question: Is there any way to use XPath contains on HTML inside an existing Java Library?</p>