|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #42260 Append Child of another DomDocument Object
Submitted: 2007-08-09 18:38 UTC Modified: 2007-08-09 18:58 UTC
From: patryk dot t dot moura at losango dot com dot br Assigned:
Status: Not a bug Package: DOM XML related
PHP Version: 5.2.4RC1 OS: Windows XP
Private report: No CVE-ID: None
 [2007-08-09 18:38 UTC] patryk dot t dot moura at losango dot com dot br
I've got two DOMDocument Objects, so, i just wish to insert some node from the second object to a node of the first object...

Reproduce code:
$obj1 = new DOMDocument();
$obj2 = new DOMDocument();
$obj1->preserveWhiteSpace = false;
$obj2->preserveWhiteSpace = false;


If I do:

$obj1->documentElement->getElementsByTagName("BODY")->item(0)->appendChild( $obj2->documentElement->getElementsByTagName("myNode")->item(0) );


$obj1->documentElement->getElementsByTagName("BODY")->item(0)->appendChild( $obj2->createElement("myNode") );

Expected result:
Expected to insert the node "myNode" of the second xml object at the "BODY" node of the first xml object... but like that, it doesn't work... =/

p.s.: the xml files are okay!!! just to you guys know!!!

Actual result:
I just get an exception that says that I can't add an DomElement with appendChild() function !!! O.o
but if I do:

$obj1->documentElement->getElementsByTagName("BODY")->item(0)->appendChild( $obj1->createElement("myNode") );


$obj1->documentElement->getElementsByTagName("BODY")->item(0)->appendChild( $obj1->documentElement->getElementsByTagName("HEAD")->item(0) );

works perfectly! i just don't know what to do... honestly!!!


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2007-08-09 18:58 UTC]
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at and the instructions on how to report
a bug at

Read the error message.
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Fri Dec 04 03:01:23 2020 UTC