You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-users@xerces.apache.org by Dana Heath <dh...@cittio.com> on 2005/10/08 10:39:24 UTC

Transfer an Element (and children) between documents

Hi all,I'm going through initiation hell, coming up to speed on the whole Xerces library and could use some help.I have a DOMElement created as a clone from a node in document 1, whereupon I would like to perform some operations and append it to document 2. Unfortunately, I get a DOMException that the document owner is incorrect. There's no apparent mechansim for me to change the owner (not that I'm even sure I'd want to do that given the possible side-effects.)Surely there's an easier way to accomplish this. Any help is greatly appreciated.-Dana Heath

Re: Transfer an Element (and children) between documents

Posted by Axel Weiß <aw...@informatik.hu-berlin.de>.
Dana Heath wrote:
> Hi all,I'm going through initiation hell, coming up to speed on the
> whole Xerces library and could use some help.I have a DOMElement
> created as a clone from a node in document 1, whereupon I would like
> to perform some operations and append it to document 2. Unfortunately,
> I get a DOMException that the document owner is incorrect. There's no
> apparent mechansim for me to change the owner (not that I'm even sure
> I'd want to do that given the possible side-effects.)Surely there's an
> easier way to accomplish this. Any help is greatly appreciated.-Dana
> Heath

Hi Dana,

you are looking for DOMDocument::importNode(.)

An easy way to move DOMElements between Documents is, e.g.

DOMElement *e1; // belongs to doc1
DOMElement *e2; // belongs to doc2

// insert e2 as a child of e1
e1->getOwnerDocument()->importNode(e2);


Cheers,
			Axel