note 54586 added to function.xpath-eval
| From: | (emailtomariuskreis.de) | Date: | Fri, 08 Jul 2005 14:26:31 +0000 |
| Subject: | note 54586 added to function.xpath-eval | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-91674@lists.php.net to get a copy of this message | ||
If the namespace is subject to change you can write even more portable code if you extend brandon
dot whitehead at orst dot edu's solution like this:
$doc = domxml_open_mem($xml);
$xpath = $doc->xpath_new_context();
$namespace = $xpath->xpath_eval('namespace-uri(//*)')->value; // returns the
namespace uri
xpath_register_ns($xpath, "pre", $namespace); // sets the prefix "pre" for the
namespace
$obj = $xpath->xpath_eval('//pre:Offer'); // finds all Offer tags
$nodeset = $obj->nodeset;
print_r($nodeset);
This code will determine the namespace of the root element and set a prefix for XPath queries. Thus
it doesn't matter if the namespace is changing in your XML (like some webservices do...)
----
Manual Page -- http://www.php.net/manual/en/function.xpath-eval.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+54586
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+54586&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+54586&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+54586&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+54586&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+54586&report=yes&reason=non-english
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+54586&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+54586&report=yes
Search -- http://master.php.net/manage/user-notes.php