Clones a new node.
var objXMLDOMNode = oXMLDOMNode.cloneNode(deep);
Object. Returns the newly created clone node.
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.5.0"); var root; var currNode; var MyNewNode; xmlDoc.async = false; xmlDoc.load("books.xml") if (xmlDoc.parseError.errorCode <> 0) { var myErr = xmlDoc.parseError; alert("You have error " + myErr.reason); } else { root = xmlDoc.documentElement; currNode = root.childNodes.item(1); MyNewNode = currNode.cloneNode(true); root.appendChild(MyNewNode); alert(xmlDoc.xml); }
Set objXMLDOMNode = oXMLDOMNode.cloneNode(deep)
An object. Returns the newly created clone node.
The following Microsoft® Visual Basic® example clones a node, and then appends it as a child of the top-level node.
Dim xmlDoc As New Msxml2.DOMDocument50 Dim root As IXMLDOMElement Dim currNode As IXMLDOMNode Dim MyNewNode As IXMLDOMNode xmlDoc.async = False xmlDoc.Load ("books.xml") If (xmlDoc.parseError.errorCode <> 0) Then Dim myErr Set myErr = xmlDoc.parseError MsgBox("You have error " & myErr.reason) Else Set root = xmlDoc.documentElement Set currNode = root.childNodes.Item(1) Set MyNewNode = currNode.cloneNode(True) root.appendChild MyNewNode MsgBox xmlDoc.xml End If
HRESULT cloneNode( VARIANT_BOOL deep, IXMLDOMNode **cloneRoot);
cloneRoot
parameter is Null.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 theDOMDocument
node, it is safer to clone the document using thesave
method, as follows.
doc.save(doc2);
To view reference information for Visual Basic, C/C++, or Script only, click the Language Filter button in the upper-left corner of the page.
nodeName Property | nodeValue Property | nodeType Property | parentNode Property | ownerDocument Property | attributes Property | childNodes Property
Applies to: IXMLDOMAttribute | IXMLDOMCDATASection | IXMLDOMCharacterData | IXMLDOMComment | DOMDocument | IXMLDOMDocumentFragment | IXMLDOMDocumentType | IXMLDOMElement | IXMLDOMEntity | IXMLDOMEntityReference | IXMLDOMNode | IXMLDOMNotation | IXMLDOMProcessingInstruction | IXMLDOMText