note 48040 added to function.dom-domxpath-query
| From: | Martin dot Honnen at gmx dot de | Date: | Thu, 09 Dec 2004 18:59:25 +0000 |
| Subject: | note 48040 added to function.dom-domxpath-query | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-81603@lists.php.net to get a copy of this message | ||
If you do not provide the second argument, the context node, then by default the context node of the
query is the root element node, not the document node.
Thus if you have
<?php
$xmlSource = <<<XMLEND
<!-- top level comment -->
<?processing-instruction arg="value"?>
<root>
<child>Kibology</child>
<child>PHP</child>
</root>
XMLEND;
$xmlDocument = new DOMDocument();
$xmlDocument->loadXML($xmlSource);
$xPathEvaluator = new DOMXPath($xmlDocument);
?>
then the following
<?php
$nodeList = $xPathEvaluator->query('self::node()');
echo 'nodeType: ' . $nodeList->item(0)->nodeType . '; nodeName: ' .
$nodeList->item(0)->nodeName ."<br>\r\n"; // nodeType is 1
?>
yields
nodeType: 1; nodeName: root
while
<?php
$nodeList = $xPathEvaluator->query('self::node()', $xmlDocument);
echo 'nodeType: ' . $nodeList->item(0)->nodeType . '; nodeName: ' .
$nodeList->item(0)->nodeName ."<br>\r\n"; // nodeType is 9
?>
yields
nodeType: 9; nodeName: #document
----
Manual Page -- http://www.php.net/manual/en/function.dom-domxpath-query.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+48040
Delete -- http://master.php.net/manage/user-notes.php?action=delete+48040&report=yes
Reason: bad code -- http://master.php.net/manage/user-notes.php?action=delete+48040&report=yes&reason=bad+code
Reason: spam -- http://master.php.net/manage/user-notes.php?action=delete+48040&report=yes&reason=spam
Reason: useless example -- http://master.php.net/manage/user-notes.php?action=delete+48040&report=yes&reason=useless+example
Reason: contains commercial links -- http://master.php.net/manage/user-notes.php?action=delete+48040&report=yes&reason=contains+commercial+links
Reason: useless note -- http://master.php.net/manage/user-notes.php?action=delete+48040&report=yes&reason=useless+note
Reject -- http://master.php.net/manage/user-notes.php?action=reject+48040&report=yes
Search -- http://master.php.net/manage/user-notes.php