title: XPath in PHPUnit testing with Zend
body: <p>I have this apparently basic code:</p>
  
  <pre><code>$docSrc = 
      '&lt;?xml version="1.0" encoding="UTF-8" ?&gt;
      &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
      &lt;head&gt;&lt;title /&gt;&lt;/head&gt;
      &lt;body&gt;&lt;p&gt;Test paragraph.&lt;/p&gt;&lt;/body&gt;
      &lt;/html&gt;';
  $domDoc = new DOMDocument();
  $domDoc-&gt;loadXML($docSrc);
  $xpath  = new DOMXPath($domDoc);
  $nodeList = $xpath-&gt;query('//p');
  $this-&gt;assertTrue($nodeList-&gt;length == 1);
  </code></pre>
  
  <p>It should succeed, but fails miserably, the length is 0. I have been looking for a solution all day, but to no avail.</p>
  
  <hr>
  
  <p>Wow thanks! It works! Unfortunately, my original code:</p>
  
  <pre><code>$query = new Zend_Dom_Query($docSrc);
  $xpathQuery = '//p';
  $result = $query-&gt;queryXpath($xpathQuery);
  $this-&gt;assertTrue($result-&gt;count() == 1);
  </code></pre>
  
  <p>thinks it is an XML and perform loadXML. Do you have any idea why this happens?</p>
  
  <hr>
  
  <p>Ok I found the culprit somewhere in the Zend Library:</p>
  
  <pre><code>if ('&lt;' . '?xml' == substr(trim($document), 0, 5)) {
      return $this-&gt;setDocumentXml($document, $encoding);
  }
  </code></pre>
  
  <p>I wonder if this is correct since it IS an XML document, but load XML does not work.</p>
  
  <hr>
  
  <p>Ok I’m doing some research. Apparently, the problem has something to do with namespaces...</p>