title: How to prevent DOMXPath from expanding HTML entities?
body: <p>I'm using DOMDocument and DOMXPath in PHP to find elements in an HTML document. 
  This document contains HTML entities like &amp;nbsp ; and I would like these entities to be preserved in the XPath output.</p>
  
  <pre><code>$doc = new DOMDocument();
  $doc-&gt;loadHTML('&lt;html&gt;&lt;head&gt;&lt;/head&gt;&lt;body&gt;&amp;nbsp;Test&lt;/body&gt;&lt;/html&gt;');
  
  $xpath = new DOMXPath($doc);
  $nodes = $xpath-&gt;query('//body');
  
  foreach($nodes as $node) {
      echo $node-&gt;textContent;
  }
  </code></pre>
  
  <p>This code produces the following output (UTF-8):</p>
  
  <pre><code>[space]Test
  </code></pre>
  
  <p>But I would like to have this:</p>
  
  <pre><code>&amp;nbsp;Test
  </code></pre>
  
  <p>Maybe it has something to do with LibXML that PHP uses internally, but I couldn't find any function that preserves the HTML entities.  </p>
  
  <p>Do you have an idea?</p>