Here you can find the source of cloneDocument(Document document)
static public Document cloneDocument(Document document)
//package com.java2s; //License from project: Apache License import javax.xml.parsers.DocumentBuilder; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerException; import javax.xml.transform.dom.DOMResult; import javax.xml.transform.dom.DOMSource; import org.w3c.dom.Document; public class Main { static private DocumentBuilder parser = null; /**/* ww w .j av a 2 s . co m*/ * XSL transform (identity) to create text from Document. */ static private Transformer identityTransformer; static public Document cloneDocument(Document document) { if (document == null) return null; Document result = newDocument(); try { identityTransformer.transform(new DOMSource(document), new DOMResult(result)); } catch (TransformerException e) { e.printStackTrace(); } return result; } static public Document newDocument() { return parser.newDocument(); } }