Easy Tutorial
❮ Dom Nodes Traverse Dom Intro ❯

XML DOM cloneNode() Method


Definition and Usage

The cloneNode() method creates an exact copy of the specified node.

This method returns the cloned node.

Syntax

Parameter Description
include_all Required. If the boolean parameter is set to true, the cloned node will clone all child nodes of the original node.

Example

The following code snippet uses loadXMLDoc() to load "books.xml" into xmlDoc, clones the first <book> node, and appends the copy to the end of the node list:

xmlDoc=loadXMLDoc("books.xml");
x=xmlDoc.getElementsByTagName('book')[0];
cloneNode=x.cloneNode(true);
xmlDoc.documentElement.appendChild(cloneNode);

// Output all title node text values
y=xmlDoc.getElementsByTagName("title");
for (i=0;i&lt;y.length;i++)
{
  document.write(y[i].childNodes[0].nodeValue);
  document.write("<br>");
}

Output:

Everyday Italian
Harry Potter
XQuery Kick Start
Learning XML
Everyday Italian

❮ Dom Nodes Traverse Dom Intro ❯