title: Using XPath in node.js
body: <p>I am building a little document parser in node.js. To test, I have <a href="https://gist.github.com/dend/b0148c00b501859a5eb3bb2b310ad1f7" rel="nofollow noreferrer">a raw HTML file</a>, that is generally downloaded from the real website when the application executes.</p>
  
  <p>I want to extract the <strong>first</strong> code example from each section of the Console.WriteLine that matches my constraint - it has to be written in C#. To do that, I have this sample XPath:</p>
  
  <pre><code>//*[@id='System_Console_WriteLine_System_String_System_Object_System_Object_System_Object_']/parent::div/following-sibling::div/pre[position()&gt;1]/code[contains(@class,'lang-csharp')]
  </code></pre>
  
  <p>If I <a href="http://videlibri.sourceforge.net/cgi-bin/xidelcgi" rel="nofollow noreferrer">test the XPath online</a>, I get the expected results, which <a href="https://gist.github.com/dend/1a3477773286075b90b20472439ee2ed" rel="nofollow noreferrer">is in this Gist</a>.</p>
  
  <p>In my node.js application, I am using <a href="https://www.npmjs.com/package/xmldom" rel="nofollow noreferrer">xmldom</a> and <a href="https://www.npmjs.com/package/xpath" rel="nofollow noreferrer">xpath</a> to try and parse that exact same information out:</p>
  
  <pre><code>var exampleLookup = `//*[@id='System_Console_WriteLine_System_String_System_Object_System_Object_System_Object_']/parent::div/following-sibling::div/pre[position()&gt;1]/code[contains(@class,'lang-csharp')]`;
  var doc = new dom().parseFromString(rawHtmlString, 'text/html');
  var sampleNodes = xpath.select(exampleLookup,doc);
  </code></pre>
  
  <p>This does not return anything, however.</p>
  
  <p>What might be going on here?</p>