You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-dev@xerces.apache.org by Vipul <vv...@unwiredsoft.com> on 2000/12/06 13:25:36 UTC

importing a node from 1 document to another

Hi
the scenario is this. i have a document. i search the document for a set of
tags n get a NodeList.
I traverse through it finding a particular Node with a perticular attribute.
Once i have found that node, i need to insert this node (and its children)
into another document and return that document.

I am using xerces 1.2.2. I tried using importNode, and also appendChild but
all of them did not copy that node to the new document.

the code is


Node temp ;

.... processing on temp....

DocumentImpl filterDoc = new DocumentImpl();
filterDoc.adoptNode(temp);



Now here, temp is in a different document and filterDoc is a different
document. so i get an error stating DOM005 Wrong Document.

Can any1 help me in this

vipul.


RE: importing a node from 1 document to another

Posted by Hans Bjurstrom <ha...@pipebeach.com>.
Hello,


you might try using ranges...
somthing like this:



import org.w3c.dom.*;
import org.w3c.dom.ranges.*;

    Range range = doc.createRange();
    range.selectNodeContents(theSelectedNode);
    DocumentFragment fragment = range.extractContents();
    nodeWhereYouWantToInsertYourSubtree.appendChild(fragment);


Regards Hans Bjurström

-----Original Message-----
From: Vipul [mailto:vveera@unwiredsoft.com]
Sent: Wednesday, December 06, 2000 1:26 PM
To: xerces-j-dev@xml.apache.org
Subject: importing a node from 1 document to another


Hi
the scenario is this. i have a document. i search the document for a set of
tags n get a NodeList.
I traverse through it finding a particular Node with a perticular attribute.
Once i have found that node, i need to insert this node (and its children)
into another document and return that document.

I am using xerces 1.2.2. I tried using importNode, and also appendChild but
all of them did not copy that node to the new document.

the code is


Node temp ;

.... processing on temp....

DocumentImpl filterDoc = new DocumentImpl();
filterDoc.adoptNode(temp);



Now here, temp is in a different document and filterDoc is a different
document. so i get an error stating DOM005 Wrong Document.

Can any1 help me in this

vipul.


---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-dev-help@xml.apache.org