|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2009-12-03 20:19 UTC] svn@php.net
[2009-12-03 20:21 UTC] rrichards@php.net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Oct 26 03:00:01 2025 UTC |
Description: ------------ I was expecting importNode to preserve attribute namespaces. It doesn't Reproduce code: --------------- <?php // PHP 5.2.* namespace bug - importNode doesn't preserve attribute namespaces $aDOM= new DOMDocument(); $aDOM->appendChild($aDOM->createElementNS('http://friend2friend.net/','f2f:a')); echo 'DOM to add into is '.$aDOM->saveXML().chr(13); $fromdom= DOMDocument::loadXML('<data xmlns:ai=" http://altruists.org " ai:attr="namespaced" />'); echo 'Dom to import from is'.$fromdom->saveXML().chr(13); $attr= $fromdom->firstChild->attributes->item(0); $aDOM->documentElement->appendChild($aDOM->importNode($attr)); echo 'Result is '.$aDOM->saveXML(); // The following script gets round this bug function importAttrNS($targetNode, $attr) { // Last modified 2009-01-26 Imports an attribute without losing the NS, if present if ($attr->prefix=='') $targetNode->appendChild($targetNode->ownerDocument->importNode($attr)); else $targetNode->setAttributeNS($attr->lookupNamespaceURI($attr->prefix), $attr->prefix.':'.$attr->name, $attr->value); } ?> Expected result: ---------------- The imported attribute should keep its namespace. Actual result: -------------- The imported attribute becomes unnamespaced.