note 45904 added to function.dom-domxpath-query

From: Date: Thu, 23 Sep 2004 00:57:41 +0000
Subject: note 45904 added to function.dom-domxpath-query
Groups: php.notes 
Request: Send a blank email to php-notes+get-77221@lists.php.net to get a copy of this message
On my PHP 5.0.1 install XPath seems to return an empty DOMNodeList no matter what if the root element has attributes. <?php $data = <<<XML <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> <head><title>DOM is pretty cool!</title></head> <body /> </html> XML; $doc = DOMDocument::loadXML($data); $xpath = new DOMXPath($doc); $nodeList = $xpath->query("//body"); // same result any XPath query echo $nodeList->length; //output is 0 ?> <?php $data = <<<XML <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html> <head><title>DOM is pretty cool!</title></head> <body /> </html> XML; $doc = DOMDocument::loadXML($data); $xpath = new DOMXPath($doc); $nodeList = $xpath->query("//body"); // same result any XPath query echo $nodeList->length; //output is 1 ?> ---- Manual Page -- http://www.php.net/manual/en/function.dom-domxpath-query.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+45904 Delete -- http://master.php.net/manage/user-notes.php?action=delete+45904&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+45904&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#77221) next »