Java XML Document Clone cloneDocument(final Document doc)

Here you can find the source of cloneDocument(final Document doc)

Description

Creates an exact clone of a Document.

License

Open Source License

Parameter

Parameter Description
doc The document being cloned.

Return

A Document with the same Element tree, or null if null is passed in.

Declaration

public static Document cloneDocument(final Document doc) 

Method Source Code


//package com.java2s;

import org.w3c.dom.Document;

public class Main {
    /**//from  w w w .j  ava  2 s.  c om
     * Creates an exact clone of a Document.
     *
     * @param doc The document being cloned.
     *
     * @return A Document with the same Element tree, or null if null is passed in.
     */
    public static Document cloneDocument(final Document doc) {

        if (doc == null) {
            throw new IllegalArgumentException("The document source cannot be null.");
        }

        // for now do this, but it may need to be changed later if this is deemed implemenation dependent
        return (Document) doc.cloneNode(true);
    }
}

Related

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