|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2006-11-03 21:12 UTC] z_rules55 at hotmail dot com
Description:
------------
Calling getElementsByTagNameNS() on a DOMDocument or a DOMElement does not return elements that are under a default namespace. The example below finds $explicit_ns_element, but not $default_ns_element.
Reproduce code:
---------------
<?php
$xml = new DOMDocument();
$namespace = 'my_namespace';
$root = $xml->appendChild($xml->createElementNS($namespace, 'root'));
$default_ns_element = $root->appendChild($xml->createElement('element', 'default_ns_element'));
$explicit_ns_element = $root->appendChild($xml->createElementNS($namespace, 'element', 'explicit_ns_element'));
foreach($xml->getElementsByTagNameNS($namespace, 'element') as $el) {
echo $el->nodeValue."\n";
}
echo "\n";
foreach($root->getElementsByTagNameNS($namespace, 'element') as $el) {
echo $el->nodeValue."\n";
}
?>
Expected result:
----------------
default_ns_element
explicit_ns_element
default_ns_element
explicit_ns_element
Actual result:
--------------
explicit_ns_element
explicit_ns_element
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Nov 03 05:00:01 2025 UTC |
Additional note: getElementsByTagName('element') does, in fact, find both nodes.$xml->createElement('element', 'default_ns_element') That's not in the default namespace, that's in no namespace at all this way. Can't work this way