note 76311 added to function.dom-domxpath-query
| From: | nicolas_rainardNOSPAM at yahoo dot fr | Date: | Tue, 10 Jul 2007 09:04:04 +0000 |
| Subject: | note 76311 added to function.dom-domxpath-query | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-128357@lists.php.net to get a copy of this message | ||
Please note that what clochix says is valid for *any* document which has a default namespace (as it
is the case for XHTML).
This document :
<?xml version="1.0" encoding="UTF-8" ?>
<root xmlns="http://www.exemple.org/namespace">
<element id="1">
...
</element>
<element id="2">
...
</element>
</element>
must be accessed this way :
$document = new DOMDocument();
$document->load('document.xml');
$xpath = new DOMXPath($document);
$xpath->registerNameSpace('fakeprefix', 'http://www.exemple.org/namespace');
$elements = $xpath->query('//fakeprefix:element');
Of course, there is no prefix in the original document, but the DOMXPath class *needs* one, whatever
it is, if you use a default namespace. It *doesn't work* if you specify an empty prefix like
this :
$xpath->registerNameSpace('', 'http://www.exemple.org/namespace');
Hope this help to spare some time...
----
Server IP: 217.174.196.197
Probable Submitter: 90.31.33.16
----
Manual Page -- http://www.php.net/manual/en/function.dom-domxpath-query.php
Edit -- https://master.php.net/note/edit/76311
Del: integrated -- https://master.php.net/note/delete/76311/integrated
Del: useless -- https://master.php.net/note/delete/76311/useless
Del: bad code -- https://master.php.net/note/delete/76311/bad+code
Del: spam -- https://master.php.net/note/delete/76311/spam
Del: non-english -- https://master.php.net/note/delete/76311/non-english
Del: in docs -- https://master.php.net/note/delete/76311/in+docs
Del: other reasons-- https://master.php.net/note/delete/76311
Reject -- https://master.php.net/note/reject/76311
Search -- https://master.php.net/manage/user-notes.php