Closed
Description
Description
The following code:
<?php
$doc = new DOMDocument();
$element = $doc->createElementNS('http://test', 'a:x');
$doc->appendChild($element);
$element1 = $doc->createElementNS('http://test', 'b:y');
$element->appendChild($element1);
$element1->appendChild($doc->createElementNS('http://test', 'b:z'));
echo $doc->saveXml();
$xpath = new DOMXPath($doc);
$xpath->registerNodeNamespaces = true;
$xpath->registerNamespace('b', 'http://test');
$elements = $xpath->query('//b:z');
foreach ($elements as $e) {
var_dump($e->nodeName);
}
$elements = $xpath->query('//*[name()="b:z"]');
echo $elements->length;
Resulted in this output:
<?xml version="1.0"?>
<a:x xmlns:a="http://test"><b:y xmlns:b="http://test"><a:z/></b:y></a:x>
string(3) "a:z"
0
But I expected this output instead:
<?xml version="1.0"?>
<a:x xmlns:a="http://test"><b:y xmlns:b="http://test"><b:z/></b:y></a:x>
string(3) "b:z"
1
Likely caused by the fix for bug #67440: append_node of a DOMDocumentFragment does not reconcile namespaces
b1d8e24
Broken since: 8.1.21 / 8.2.8
Last known good: 8.1.20 / 8.2.7
I think the following is relevant in this context, explaining why XML C14N explicitly excluded XML namespace prefix rewriting: https://datatracker.ietf.org/doc/html/rfc3076#section-4.4
PHP Version
PHP 8.1.24
Operating System
MacOS Ventura 13.6