Re: xpath_register_ns problem
| From: | Dan Allen | Date: | Tue, 11 Jun 2002 09:21:13 +0000 |
| Subject: | Re: xpath_register_ns problem | ||
| References: | 1 | Groups: | php.dev |
| Request: | Send a blank email to php-dev+get-85128@lists.php.net to get a copy of this message | ||
Dan Allen (dan@mojavelinux.com) wrote:
> I was testing out this function today (xpath_register_ns) and I
> found a possible problem in its implementation. If you use several
> namespaces in you document and then define a last one to be the
> default namespace, how are you supposed to register this with the
> php function. Example:
>
> <?xml version="1.0" encoding="utf-8"?>
> <rdf:RDF
> xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"…×Êé
> mlTËaü;8
> xmlns:dc="http://purl.org/dc/elements/1.1/"
>
> xmlns:pl="http://mojavelinux.com/rss/1.0/modules/places"
> xmlns="http://purl.org/rss/1.0/"
> >
> <channel
> rdf:about="http://mojave.mojavelinux.com/newsletter/">
> <title>Local Sights and Attractions in Washington/Balimore for the Dan &
> Sarah Wedding</title>
>
> <link>http://mojave.mojavelinux.com/newsletter/</link>
> <description>Places in the Washington/Baltimore area where our guest may entertain
> themselves.</description>
> (clip...)
>
> Now if you run the query
>
> $ctx->xpath_register_ns('rdf',
> 'http://www.w3.org/1999/02/22-rdf-syntax-ns#');
> $ctx->xpath_register_ns('dc',
> 'http://purl.org/dc/elements/1.1/');
> $ctx->xpath_register_ns('pl',
> 'http://mojavelinux.com/rss/1.0/modules/places');
> $ctx->xpath_register_ns('',
> 'http://purl.org/rss/1.0/');
> $ctx->xpath_eval('//channel');
>
> You get no results. However, if you replace the last namespace
> declaration with the name of 'rss' and change call the tags to
> <rss:*> and then do the query
>
> $ctx->xpath_eval('//rss:channel');
>
> You get the expected results. So basically, it seems that the
> xpath_register_ns function does not allow you to register a default
> namespace.
>
As a follow up to this, how are you supposed to tell what namespaces
the xml document has...should this be done automatically?
Dan
--
________________________________________________________________
Daniel Allen, <dan@mojavelinux.com>
http://www.mojavelinux.com/
________________________________________________________________
There is no such thing as a casual knowledge of xslt, either
you know everything about it or you are sitting in the creek.
________________________________________________________________