Java XML Document Clone copy(Document from, Document to)

Here you can find the source of copy(Document from, Document to)

Description

copy

License

Apache License

Declaration

public static void copy(Document from, Document to) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

public class Main {

    public static void copy(Document from, Document to) {
        Element fromRootElem = from.getDocumentElement();
        Element toRootElem = to.getDocumentElement();
        Node childNode, importedNode;
        NodeList toChildNodes = fromRootElem.getChildNodes();
        for (int i = 0; i < toChildNodes.getLength(); i++) {
            childNode = toChildNodes.item(i);
            importedNode = to.importNode(childNode, true);
            toRootElem.appendChild(importedNode);
        }//from w  ww.  ja va2  s .  c  om
    }
}

Related

  1. cloneDocument(final Document doc)
  2. cloneDOM(final Document src)
  3. cloneDOM(Node node, Document document)
  4. cloneNode(Document d, Node n)
  5. cloneNode(Document document, Node node, boolean deep)
  6. copyChildren(Document new_doc, Node node, Node new_node)
  7. copyChildren(Element from, Element to, Document doc)
  8. copyChildren(final Document newDoc, final Node node, final Node newNode)
  9. copyDocument(Document document)