Programmer's Guide > Programming and Scripting Techniques > Basic Document Manipulation Using the DOM and AOM > Selecting, Copying, Moving Content > Copying and Pasting within a Document
  
Copying and Pasting within a Document
A copy and paste within a document can be done by cloning the contents of chapter one before inserting them before chapter three. In this example, the result will be two copies of chapter one in the document; one before and one after chapter two.
var doc = Application.openDocument("sample1.xml");
var chapters=doc.getElementsByTagName("chapter");
var chapter1 = chapters.item(0);
var chapter3 = chapters.item(2);
var book = doc.getElementsByTagName("book").item(0);
var range = doc.createRange();
range.setStartBefore(chapter1);
range.setEndAfter(chapter1);
var clone = range.cloneContents();
book.insertBefore(clone,chapter3);
range.detach();