Java examples for XML:DOM
Copying a Subtree of Nodes in a DOM Document
import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.NodeList; public class Main { public static void main(String[] args) { Document doc = null;/*www . j a v a 2 s. c o m*/ NodeList list = doc.getElementsByTagName("entry"); Element element = (Element) list.item(0); // Make a copy of the element, including any child nodes Element dup = (Element) element.cloneNode(true); // Insert the copy immediately after the cloned element element.getParentNode().insertBefore(dup, element.getNextSibling()); } }