Programmer's Guide > Programming and Scripting Techniques > Basic Document Manipulation Using the DOM and AOM > Selecting, Copying, Moving Content > Copying and Pasting between Documents
  
Copying and Pasting between Documents
Content can also be moved between documents using Document.importNode. The code in this example results in a copy and paste without the need to clone the region from the first document. This is because Document.importNode does not alter or remove content from the original document; it creates a new copy of the source node — in effect, cloning it. This example also demonstrates the use of ADocument.openDocument, the use of optional flags and path parameters on ADocument.save, and ADocument.close.
var doc1 = Application.openDocument("sample1.xml");
var doc2 = Application.openDocument("sample2.xml");
//Get the first chapter from sample1.xml and sample2.xml
var sample1Chapter = doc1.getElementsByTagName("chapter").item(0);
var sample2Chapter = doc2.getElementsByTagName("chapter").item(0);
var book = doc2.getElementsByTagName("book").item(0);
//Import the chapter from sample1.xml into sample2.xml
var newChapter = doc2.importNode(sample1Chapter,true);
//insert the chapter
book.insertBefore(newChapter,sample2Chapter);
//SAVE_NAC_ENTREF(0x0400) - write non-ascii characters as
// character entity references
doc2.save(0x0400, "newSample2.xml");
doc1.close();
doc2.close();
To execute a cut and paste between documents, select and delete the contents in the original document after inserting it in the target document.