xpath_register_ns problem
| From: | Dan Allen | Date: | Tue, 11 Jun 2002 09:19:41 +0000 |
| Subject: | xpath_register_ns problem | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-85127@lists.php.net to get a copy of this message | ||
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#"
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.
Dan
--
________________________________________________________________
Daniel Allen, <dan@mojavelinux.com>
http://www.mojavelinux.com/
________________________________________________________________
"When you're raised by the Jesuits, you become either obedient
or impertinent"
-- Jack McCoy, "Law and Order"
________________________________________________________________