merge two domDocuments
| From: | Arno Mittelbach | Date: | Mon, 17 May 2004 15:25:26 +0000 |
| Subject: | merge two domDocuments | ||
| Groups: | php.xml.dev | ||
| Request: | Send a blank email to php-xml-dev+get-372@lists.php.net to get a copy of this message | ||
Hi,
I have two domDocuments and I wanted the root element of one of them to be a
child element of the other Document.
So what I did was.
$oDomDocA = new domDocument();
$oDomDocA->appendChild( new domElement( 'root' ) );
$oRoot = $oDomDocA->documentElement;
$oDomDocB = new domDocument();
$oDomDocB->Load( 'somexml.xml' );
/* append domdocB to A */
$oRootB = $oDomDocB->documentElement;
$oToAppend = $oDomDocA->importNode( $oRootB );
$oRoot->appendChild( $oToAppend );
Everything works fine, but only the first level of $oDomDocB is 'included'
(probably appendChild includes just the first level and no grandchildren).
Is there a way to 'adopt' an Element with all its children or do I have to
do this recursively?
regards,
Arno