Java tutorial
//package com.java2s; import org.w3c.dom.Document; import org.w3c.dom.Node; public class Main { /** * Returns a new copy of the given node using the specified document as a * factory for new nodes. * * @param doc the document used as a factory for new nodes * @param node the node to copy * @return a new copy of the given node using the specified document as a * factory for new nodes. */ @SuppressWarnings("unchecked") public static <E extends Node> E newCopy(Document doc, E node) { E result = (E) node.cloneNode(true); return (E) doc.adoptNode(result); } }