|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2013-08-02 07:12 UTC] 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
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Oct 29 13:00:01 2025 UTC |
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).