Re: [PHP-XML-DEV] merge two domDocuments

[email protected] (Adam Maccabee Trachtenberg) Thu, 20 May 2004 13:51:30 -0400 (EDT)
Newsgroups php.xml.dev
Message-ID <[email protected]>
On Mon, 17 May 2004, Arno Mittelbach wrote:

> /* 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?

Pass true as the second parameter to importNode():

$oToAppend = $oDomDocA->importNode( $oRootB, true );

-adam

-- 
[email protected]
author of o'reilly's php cookbook
avoid the holiday rush, buy your copy today!