Java XML Document Clone cloneDOM(final Document src)

Here you can find the source of cloneDOM(final Document src)

Description

Create a clone of a DOM object

License

Open Source License

Declaration

public static Document cloneDOM(final Document src) throws TransformerException 

Method Source Code

//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*/
}

Related

  1. clone(Document inDoc)
  2. cloneAndAppend(Document document, Node node)
  3. cloneDocument(Document document)
  4. cloneDocument(final Document doc)
  5. cloneDocument(final Document doc)
  6. cloneDOM(Node node, Document document)
  7. cloneNode(Document d, Node n)
  8. cloneNode(Document document, Node node, boolean deep)
  9. copy(Document from, Document to)