|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2021-09-23 11:21 UTC] cmb@php.net
[2021-09-23 11:21 UTC] cmb@php.net
-Status: Open
+Status: Verified
[2023-01-21 09:19 UTC] rajeshvarma201819 at gmail dot com
[2024-03-09 16:09 UTC] nielsdos@php.net
-Status: Verified
+Status: Closed
-Assigned To:
+Assigned To: nielsdos
[2024-03-09 16:09 UTC] nielsdos@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Nov 03 03:00:01 2025 UTC |
Description: ------------ A child node created with DOMDocument::createElement() added to an element with a non-empty default namespace internally does not seem to inherit the default namespace of the parent, while when saving the XML it looks like it does. And imho it should inherit the namespace, because a node created with createElement() does not yet have a namespace until it is added somewhere in the document (hence parameter name localName). In contrary a node created with createElementNS() keeps its explicit namespace once added anywhere. Not sure if this a libxml bug, or a bug in PHP xml extension. Test script: --------------- <?php $dom = new \DOMDocument(); $dom ->appendChild($dom->createElementNS('some:namespace', 'foo')) ->appendChild($dom->createElement('bar')); echo ($xml = $dom->saveXML()); $xpath = new \DOMXPath($dom); $xpath->registerNamespace('n', 'some:namespace'); echo count($xpath->query('/n:foo/bar')) . " should be 0\n"; echo count($xpath->query('/n:foo/n:bar')) . " should be 1\n\n"; // $dom = new \DOMDocument(); $dom->loadXml($xml); echo ($xml = $dom->saveXML()); $xpath = new \DOMXPath($dom); $xpath->registerNamespace('n', 'some:namespace'); echo count($xpath->query('/n:foo/bar')) . " should be 0\n"; echo count($xpath->query('/n:foo/n:bar')) . " should be 1\n\n"; Expected result: ---------------- See test script and output. Actual result: -------------- See test script and output.