Re: XPath and Multiple Namespaces
| From: | Daniel Pupius | Date: | Tue, 02 Dec 2003 09:41:05 +0000 |
| Subject: | Re: XPath and Multiple Namespaces | ||
| References: | 1 | Groups: | php.xml.dev |
| Request: | Send a blank email to php-xml-dev+get-262@lists.php.net to get a copy of this message | ||
In case anyone else has this problem, someone contacted me directly and
prompted me to upgrade the version of libxml2.
It now works a treat.
"Daniel Pupius" <dan.pupius@actelearning.com> wrote in message
news:20031201164531.35576.qmail@pb1.pair.com...
> I'm having nightmares with xpath queries on xml documents with multiple
> namespaces. For example, take the following test file:
>
> <test xmlns="http://main.com"
> xmlns:sub="http://sub.com">
> <item>
> <subitem>
> <sub:testnode>Testing 1 2 3</sub:testnode>
> </subitem>
> </item>
> </test>
>
> You'd expect that I could access the testnode using:
> /i:test/i:item/i:subitem/sub:testnode
>
> Where i is a reference to the default namespace specified using
> xpath_register_ns() as was suggested in a post on one of the news groups.
>
> But it seems that xpath_register_ns() overwrites previously specified
> namespaces, for example:
>
> 1 $xpath = $dom->xpath_new_context();
> 2 xpath_register_ns($xpath,"sub",
> "http://sub.com");
> 3 xpath_register_ns($xpath,"i",
> "http://main.com");
> 4 $xnode = xpath_eval($xpath,"/i:test");
> 5 print_r($xnode);
>
> Will find the root node, however swap lines 2 and 3 around and it will
fail.
> So my problem seems to stem from registering multiple name spaces.
>
> Hope this makes sense and someone can help.
>
> Regards
>
> Dan
>
> ---------------------------------------------
> act : making e-learning work
> ---------------------------------------------
>
> Daniel Pupius BSc(hons) MA
> Senior Lead Developer
> email: daniel.pupius@actelearning.com
>
> New Oxford House
> 30 Barker's Pool
> Sheffield S1 2HB
> Tel: 0114 278 0798
> Fax: 0114 249 1773
>
> ---------------------------------------------
> http://www.actelearning.com/
> ---------------------------------------------