Copy an XML document : DOM Document « XML « Java






Copy an XML document

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

public class Utils {

  /**
   * Copy an XML document, adding it as a child of the target document root
   * @param source Document to copy
   * @param target Document to contain copy
   */
  public static void copyDocument(Document source, Document target)
  {
    Node node = target.importNode(source.getDocumentElement(), true);

    target.getDocumentElement().appendChild(node);
  }


}

   
    
    
    
  








Related examples in the same category

1.Create DOM Document out of string
2.Create Document with root QName
3.Create Empty DOM Document
4.Displays a DOM document in a tree control.
5.New Document From InputStream
6.New Document From String
7.load Document by element
8.load Document from InputStream
9.get Document Element from a file
10.Start a new XML Document
11.Document To String
12.Utility class to print out DOM
13.Return a new document, ready to populate
14.Read Xml from InputStream and return Document
15.Read Xml from Reader and return Document
16.Gets the owner document of a node.
17.Creates an element on the given document.
18.Loads a W3C XML document from a file.
19.Your Own XML Reader