cloneNode Method
Clones a new node.
var objXMLDOMNode = oXMLDOMNode.cloneNode(deep);
Parameters
Return Value
Object. Returns the newly created clone node.
Example
The following script example clones a node, and then appends it as a child of the top-level node.
var xmlDoc = new ActiveXObject("Msxml2.DOMDocument.6.0"); var root; var currNode; var MyNewNode; xmlDoc.async = false; xmlDoc.loadXML("<root><book/><AUTHOR/></root>") if (xmlDoc.parseError.errorCode != 0) { var myErr = xmlDoc.parseError; WScript.Echo("You have error " + myErr.reason); } else { root = xmlDoc.documentElement; currNode = root.childNodes.item(1); MyNewNode = currNode.cloneNode(true); root.appendChild(MyNewNode); WScript.Echo(xmlDoc.xml); }
Output
<root><book/><AUTHOR/><AUTHOR/></root> | |
The cloned node has the same property values as this node for the following properties: nodeName property, nodeValue property, nodeType property, parentNode property, ownerDocument property, and, if it is an element, attributes property. The value of the clone's childNodes property depends on the setting of the deep flag parameter.
Note
|
|---|
|
If the node is the DOMDocument node, it is safer to clone the document using the save method, as follows. |
Note