php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #65375 DOMXPath query registerNodeNS produces unexpected behavior
Submitted: 2013-08-02 07:12 UTC Modified: 2013-12-03 08:10 UTC
From: goetas at lignano dot it Assigned:
Status: Not a bug Package: DOM XML related
PHP Version: 5.4.17 OS: ubuntu 12.04
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: goetas at lignano dot it
New email:
PHP Version: OS:

 

 [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

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-12-02 17:20 UTC] mike@php.net
-Status: Open +Status: Not a bug
 [2013-12-02 17:20 UTC] 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-12-03 08:08 UTC] 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-03 08:10 UTC] mike@php.net
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.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sun May 04 04:01:29 2025 UTC