XML DOM cloneNode()Methods
Node object
Definition and Usage
The cloneNode() method creates an exact copy of the specified node.
This method returns the cloned node.
Syntax
nodeObject.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, clone the first <book> node and append it 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
Harry Potter
XQuery Kick Start
Learning XML
Everyday Italian
Try it Yourself »
Node objectother extensions