Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > [HELP] Create a DOM using a node from another node

Thread Tools

[HELP] Create a DOM using a node from another node
Posts: n/a

I'm posting an answer for people looking about the same thing.

private Document createNewDOM(Document srcDocument) {

try {
//Create the resulting DOM
Document resultDocument =
DocumentBuilderFactory.newInstance().newDocumentBu ilder().newDocument();

//import an element (here, it is the root element) from first DOM
DocumentFragment df = srcDocument.createDocumentFragment();
documentFragment.appendChild(srcDocument.getDocume ntElement());

//Create the Node to append to the new DOM
Node importNode = resultDocument.importNode(documentFragment,


catch (Exception e) {

finally {
return resultDocument;

hope that help!!
Reply With Quote

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
Nokogiri: Is there a way to append DOM to another DOM? Joshua Muheim Ruby 2 10-13-2009 10:41 PM
xsl variable $node/text() but $node can non-node-set help! Tjerk Wolterink XML 2 08-24-2006 03:28 AM
How to set the node indent property between the parent node and the leaf node ASP .Net 0 02-13-2006 07:11 PM
Select Node Using position or value of another node. Eddy C XML 6 10-17-2005 11:02 PM
Create text node in a DOM tree Matt Java 0 05-23-2004 12:39 AM