title: Using xmllint and xpath with a less-than-perfect HTML document?
body: <p>I have an HTML page that is generated by an existing tool - I cannot change the output of this tool.</p>
  
  <p>However, I want to use <code>xmllint</code> with the <code>--xpath</code> option to pick out a few specific pieces of information from the downloaded webpage. The problem is that the page starts with:</p>
  
  <p><code>&lt;html lang=en&gt;&lt;head&gt;...</code></p>
  
  <p>And <code>xmllint</code> throws errors nearly immediately:</p>
  
  <pre><code>html.out:2: parser error : AttValue: " or ' expected
  &lt;html lang=en&gt;&lt;head&gt;
             ^
  </code></pre>
  
  <p>The issue certainly seems to be the missing enclosing quotation marks around the value of the <code>lang</code> attribute. The entire page is full of this kind of issue. (Though only sporadically.)</p>
  
  <p>Nearly every browser can parse this just fine - how can I convince <code>xmllint</code> to do so as well? I would like to avoid having to inject an intermediate step to "fix" the file. Instead, I would like to either:</p>
  
  <p>1) Find a flag, validation option, etc. that helps the parser along, or:</p>
  
  <p>2) Use some other tool. (But what? <code>xmllint</code> is always my go-to for command line XPath commands.)</p>
  
  <p>Further, using just <code>xpath</code> results in:</p>
  
  <pre><code>&gt; xpath html.out '//myquery...'
  
  not well-formed (invalid token) at line 2, column 11, ...
  </code></pre>