merge two domDocuments

[email protected] ("Arno Mittelbach") Mon, 17 May 2004 17:25:26 +0200
Newsgroups php.xml.dev
Message-ID <[email protected]>
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