note 45863 added to function.dom-domxpath-registernamespace
| From: | gem at rellim dot com | Date: | Tue, 21 Sep 2004 23:43:12 +0000 |
| Subject: | note 45863 added to function.dom-domxpath-registernamespace | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-77131@lists.php.net to get a copy of this message | ||
Here is a working code sample:
$s =<<<EOT
<rootname xmlns="http://www.some.org/"
xml:lang="en-US">
<childnode>Some text</childnode>
</rootname>
EOT;
$xml = DOMDocument::loadXML( $s);
$objectXPath = new DOMXPath($xml);
# this returns nothing
$NodeList = $objectXPath->query("/rootname/childnode");
echo "Length /rootname/childnode {$NodeList->length}<br>\n";
$objectXPath->registerNamespace( 'pre', "http://www.some.org/");
# this returns what you expect
$NodeList = $objectXPath->query("/pre:rootname/pre:childnode");
echo "Length /pre:rootname/pre:childnode {$NodeList->length}<br>\n";
Run it and you get:
Length /rootname/childnode 0
Length /pre:rootname/pre:childnode 1
----
Manual Page -- http://www.php.net/manual/en/function.dom-domxpath-registernamespace.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+45863
Delete -- http://master.php.net/manage/user-notes.php?action=delete+45863&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+45863&report=yes
Search -- http://master.php.net/manage/user-notes.php