Java XML Document Clone cloneDocument(Document document)

Here you can find the source of cloneDocument(Document document)

Description

clone Document

License

Apache License

Declaration

static public Document cloneDocument(Document document) 

Method Source Code

//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();
    }
}

Related

  1. clone(Document doc)
  2. clone(Document inDoc)
  3. cloneAndAppend(Document document, Node node)
  4. cloneDocument(final Document doc)
  5. cloneDocument(final Document doc)
  6. cloneDOM(final Document src)
  7. cloneDOM(Node node, Document document)