XML DOM cloneNode()Methods


Element object

Definition and Usage

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

This method returns the cloned node.

Syntax

cloneNode(include_all)

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 usesloadXMLDoc()put "books.xml" Load into xmlDoc, copy the first <book> node and add the copy to the end of the node list:

Example

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<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

Try it Yourself »

Element objectother extensions