Bug #65375 [Nab]: DOMXPath query registerNodeNS produces unexpected behavior
| From: | mike@php.net | Date: | Tue, 03 Dec 2013 08:10:24 +0000 |
| Subject: | Bug #65375 [Nab]: DOMXPath query registerNodeNS produces unexpected behavior | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-183087@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=65375&edit=1
ID: 65375
Updated by: mike@php.net
Reported by: goetas at lignano dot it
Summary: DOMXPath query registerNodeNS produces unexpected
behavior
Status: Not a bug
Type: Bug
Package: DOM XML related
Operating System: ubuntu 12.04
PHP Version: 5.4.17
Block user comment: N
Private report: N
New Comment:
Yeah, unfortunately we're a bit too late in the game and changing the default value of that
parameter would probably be a bad idea.
Previous Comments:
------------------------------------------------------------------------
[2013-12-03 08:08:43] goetas at lignano dot it
I agree with you, using register_node_ns==true then the namespaces of the context node should be
used.
$xpath = new DOMXPath($dom);
$xpath->registerNamespace("ns2", "http://my.com/ns1");
echo $xpath->query("//ns2:tag-2", $dom->documentElement)->length; // expected to
be 1, actually 0
It is really strange that i have to "remember" the existence of
"register_node_ns" parameter and care about it.
register_node_ns option will overwrite previously registered namespaces using registerNamespace.
registerNamespace() should have more precedence than register_node_ns.
I think that register_node_ns should not overwrite previously registered namespaces with
registerNamespace.
(optionally register_node_ns should be false by default, but it will create a BC issue, and may be
not a good idea).
------------------------------------------------------------------------
[2013-12-02 17:20:11] mike@php.net
If register_node_ns==true then the namespaces of the context node are used. If the context node is
not given, the document's root node is used.
------------------------------------------------------------------------
[2013-08-02 07:12:48] goetas at lignano dot it
Description:
------------
registerNodeNS option (default to true) added with php 5.3.3 produces unexpected behavior and BC
issue.
$registerNodeNS = true seems to remove (overwrite) registered namespaces with
DOMXPath::registerNamespace() method,
Similar problem has been reported with #55700
Test script:
---------------
<?php
$dom = new DOMDocument('1.0', 'UTF-8');
$dom->loadXML('
<ns1:tag xmlns:ns1="http://my.com/ns1"
xmlns:ns2="http://my.com/ns2">
<ns1:tag-2/>
<ns2:extra/>
</ns1:tag>');
$xpath = new DOMXPath($dom);
$xpath->registerNamespace("ns2", "http://my.com/ns1");
echo $xpath->query("//ns2:tag-2", null, false)->length."\n";
echo $xpath->query("//ns2:tag-2", null, true)->length,"\n";
/*
* registerNodeNS option should skip prefix registration if
* same prefix is already registered with registerNamespace() method.
*/
Expected result:
----------------
1
1
Actual result:
--------------
1
0
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=65375&edit=1