[HELP] Create a DOM using a node from another node

Y

yio

Hi,

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().newDocumentBuilder().newDocument();

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

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

resultDocument.appendChild(importNode);
}

catch (Exception e) {
e.printlnStackTrace();
}

finally {
return resultDocument;
}


hope that help!!
Bye
Lionel
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top