Dear Erik,
That exactly solved my problem. Thank you very much!
On Tue, 11 Nov 2003, Erik Rydgren wrote:
> Well I have no problems replacing a document root with the 2.2.0
> codebase. I use the following code. The code is pure DOM so no extra
> fancy stuff, don't mind the wrapper classes.
>
> cDocument* poDoc1 = GetDOMImplementation().CreateDocument("", "test",
> NULL);
> cDocument* poDoc2 = GetDOMImplementation().CreateDocument("", "test2",
> NULL);
> poDoc2->GetDocumentElement()->AppendChild(poDoc2->CreateElement("elem1")
> ->cast());
> poDoc2->GetDocumentElement()->AppendChild(poDoc2->CreateElement("elem2")
> ->cast());
> poDoc2->GetDocumentElement()->AppendChild(poDoc2->CreateElement("elem3")
> ->cast());
>
> cNode* poClone =
> poDoc1->ImportNode(poDoc2->GetDocumentElement()->cast(), true);
> poDoc1->ReplaceChild(poClone, poDoc1->GetDocumentElement()->cast());
>
> // HERE the document root of poDoc1 is test2 with 3 children
>
> Best regards
> / Erik
>
> > -----Original Message-----
> > From: Chris Cheung [mailto:[EMAIL PROTECTED]
> > Sent: den 11 november 2003 06:54
> > To: [EMAIL PROTECTED]; [EMAIL PROTECTED]
> > Cc: Anthony Chan
> > Subject: Clone a DOM subtree to the root of a new DOMDocument
> efficiently
> > ?
> >
> > Dear all,
> >
> > Very often I need to clone a DOM subtree to a new DOMDocument and
> make
> > the root of the subtree be the document element of the new
> DOMDocument.
> > However, it seems that in Xerces-C++/Perl, the document element is
> > created when creating the DOMDocument (via
> > DomImplementation::createDocument) and cannot be replaced afterward.
> > Hence I cannot use the DOMDocument::importNode to directly deep clone
> the
> > root node of the source subtree, but rather I have to copy its
> > attributes and child nodes one by one (in Perl code):
> >
--
Best Regards,
Chris Cheung
Center for Large-Scale Computation
Have a nice day!
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]