Bug #44773 [Com]: DOMDocumentFragment::appendXML() stumbles over namespaces

From: Date: Mon, 18 Aug 2014 05:54:27 +0000
Subject: Bug #44773 [Com]: DOMDocumentFragment::appendXML() stumbles over namespaces
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-187160@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=44773&edit=1 ID: 44773 Comment by: fuzzy76 at fuzzy76 dot net Reported by: daniel dot gorski at develnet dot org Summary: DOMDocumentFragment::appendXML() stumbles over namespaces Status: Not a bug Type: Bug Package: DOM XML related Operating System: Linux PHP Version: 5.3CVS-2008-04-18 (CVS) Block user comment: N Private report: N New Comment: I beg to differ. If a DocumentFragment does not know which namespaces it is defined for, the current behavior makes no sense. Ofcourse prefixes won't be defined when NO prefixes are defined. This breaks pretty common functionality, like xmlseclib's encryption/decryption of nodes. Previous Comments: ------------------------------------------------------------------------ [2008-04-18 12:30:53] chregu@php.net Thank you for taking the time to write to us, but this is not a bug. Please double-check the documentation available at http://www.php.net/manual/ and the instructions on how to report a bug at http://bugs.php.net/how-to-report.php That's expected behaviour as the namespace is not defined in your DocumentFragment (and DocumentFragment doesn't have $doc- >documentElement as parentNode where the namespace would have been defined in your example) $frag->appendXML('<name:element xmlns:name="...">text</name:element>'); solves the problem (but I'm sure, you already knew that :) ) ------------------------------------------------------------------------ [2008-04-18 12:06:15] daniel dot gorski at develnet dot org Correction, added missing namespace prefix "name": Expected result: ---------------- <?xml version="1.0"?> <root xmlns:name="..."><name:element>text</name:element></root> ------------------------------------------------------------------------ [2008-04-18 12:04:38] daniel dot gorski at develnet dot org Description: ------------ The DOMDocumentFragment::appendXML() function spits warnings if it comes to insertion of XML with namespace-prefixed elements. This of course would make sense if the namespaces were not definied, but they are - at least in the parent document. regards dtg Reproduce code: --------------- <?php error_reporting(E_ALL); $doc = new DOMDocument(); $doc->loadXML('<root xmlns:name="..."/>'); $frag = $doc->createDocumentFragment(); $frag->appendXML('<name:element>text</name:element>'); $doc->documentElement->appendChild($frag); echo htmlentities($doc->saveXML()); ?> Expected result: ---------------- <?xml version="1.0"?> <root xmlns:name="..."><element>text</element></root> Actual result: -------------- Warning: DOMDocumentFragment::appendXML() [domdocumentfragment.appendxml]: namespace error : Namespace prefix name on element is not defined in ... on line 9 Warning: DOMDocumentFragment::appendXML() [domdocumentfragment.appendxml]: <name:element>text</name:element> in ... on line 9 Warning: DOMDocumentFragment::appendXML() [domdocumentfragment.appendxml]: ^ in ... on line 9 <?xml version="1.0"?> <root xmlns:name="..."><element>text</element></root> ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=44773&edit=1

« previous php.bugs (#187160) next »