php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #44773 DOMDocumentFragment::appendXML() stumbles over namespaces
Submitted: 2008-04-18 12:04 UTC Modified: 2008-04-18 12:30 UTC
From: daniel dot gorski at develnet dot org Assigned:
Status: Not a bug Package: DOM XML related
PHP Version: 5.3CVS-2008-04-18 (CVS) OS: Linux
Private report: No CVE-ID: None
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
32 - 4 = ?
Subscribe to this entry?

 
 [2008-04-18 12:04 UTC] 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>

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-04-18 12:06 UTC] 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:30 UTC] 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 :) )
 [2014-08-18 05:54 UTC] fuzzy76 at fuzzy76 dot net
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.
 [2014-10-27 20:10 UTC] ppkrauss at gmail dot com
I agree fuzzy76, the current behavior makes no sense. Need something like setAttributeNS() for the context (all fragment not only a tag), or need to  inherit/accept the DomDocument namespace-definitions.
 [2014-10-27 21:06 UTC] don dot lacuran at gmail dot com
I have to agree, this is a bug. If the fragment is being created off the original document, and the original document has the namespaces defined ... the fragment should inherit the same namespaces.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Oct 31 22:01:27 2024 UTC