Here you can find the source of cloneDOM(final Document src)
public static Document cloneDOM(final Document src) throws TransformerException
//package com.java2s; //License from project: Open Source License import javax.xml.transform.Transformer; import javax.xml.transform.TransformerException; import javax.xml.transform.TransformerFactory; import javax.xml.transform.dom.DOMResult; import javax.xml.transform.dom.DOMSource; import org.w3c.dom.Document; public class Main { private static TransformerFactory sTransformerFactory = TransformerFactory.newInstance(); /** Create a clone of a DOM object */ public static Document cloneDOM(final Document src) throws TransformerException { // Answer from // http://stackoverflow.com/questions/279154/how-can-i-clone-an-entire-document-using-the-java-dom final Transformer transformer = sTransformerFactory.newTransformer(); final DOMSource srcDom = new DOMSource(src); final DOMResult resultDom = new DOMResult(); transformer.transform(srcDom, resultDom); return (Document) resultDom.getNode(); }/* w w w. j a va 2 s . c o m*/ }