Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > Howto: Extract Node/sub-tree of a Document and form a new XMLDocument

Reply
Thread Tools

Howto: Extract Node/sub-tree of a Document and form a new XMLDocument

 
 
Casper B
Guest
Posts: n/a
 
      01-25-2005
As the topic says, I am wondering how (in Java) I can extract a sub-tree
of a org.w3c.dom.Document and form a brand new one. I use Oracle's
XMLDocument implementation and have been playing around with
DocumentFragment etc. but somehow I always end up creating only the
single node and not its sub-nodes.

/Casper
 
Reply With Quote
 
 
 
 
Stanimir Stamenkov
Guest
Posts: n/a
 
      01-29-2005
/Casper B/:

> As the topic says, I am wondering how (in Java) I can extract a sub-tree
> of a org.w3c.dom.Document and form a brand new one. I use Oracle's
> XMLDocument implementation and have been playing around with
> DocumentFragment etc. but somehow I always end up creating only the
> single node and not its sub-nodes.


You probably need the 'Document.importNode' method:

http://www.w3.org/TR/DOM-Level-2-Cor...ent-importNode
http://java.sun.com/j2se/1.4.2/docs/...ode,%20boolean)

Notice the 'deep' parameter:

> deep - If true, recursively import the subtree under the specified
> node; if false, import only the node itself, as explained above.
> This has no effect on Attr, EntityReference, and Notation nodes.


Something like:

Document doc1;
Element elem1; // element from 'doc1'

Document doc2;
Element elem2; // element from 'doc2'

// perform a deep copy of 'elem1' from 'doc1' adding
// it as child of 'elem2' from 'doc2'
elem2.appendChild(doc2.importNode(elem1, true));

--
Stanimir
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do i extract vidios when winrar wont extract them??? help plzzzzzzzz smuttdog@sc.rr.com Computer Support 2 12-23-2007 07:03 AM
Extract a <node> as a new XMLDocument? Carlos Albert ASP .Net 4 01-20-2006 02:30 PM
Re: Can an XmlNode from one XmlDocument be copied to another XmlDocument? Bob ASP .Net 0 07-21-2004 11:49 PM
Using ASP.Net controls within an XmlDocument instance -- and post form question? KathyB ASP .Net 0 07-25-2003 06:16 PM
loading xmlcontent from one xmldocument into another xmldocument Shoval Tomer ASP .Net 0 07-09-2003 04:29 PM



Advertisments