Here you can find the source of copyChildren(Element from, Element to, Document doc)
public static void copyChildren(Element from, Element to, Document doc)
//package com.java2s; import org.w3c.dom.Node; import org.w3c.dom.Element; import org.w3c.dom.Document; public class Main { public static void copyChildren(Element from, Element to, Document doc) { Node child = from.getFirstChild(); while (child != null) { to.appendChild(doc.importNode(child, /*deep*/ true)); child = child.getNextSibling(); }/* w w w . ja v a 2s. co m*/ } }