Microsoft XML SDK 2.6 - XML Reference

cloneNode Method

Creates a new node that is an exact clone of this node.

objXMLDOMNode = oXMLDOMNode.cloneNode(deep)

Parameters

deep
Boolean. Flag that indicates whether to recursively clone all nodes that are descendants of this node. If True, create a clone of the complete tree below this node. If False, clone this node and its attributes only.

Return Value

Object. Returns the newly created clone node.

Remarks

The cloned node has the same property values as this node for the following properties: nodeName, nodeValue, nodeType, parentNode, ownerDocument, and (if it is an element) attributes. The value of the clone's childNodes collection depends on the setting of the deep flag parameter.

Example

The following example clones a node, and then appends it as a child of the top-level node:

Dim xmlDoc
Dim root
Dim currNode
Dim MyNewNode
Set xmlDoc = CreateObject("Msxml2.DOMDocument")
xmlDoc.async = False
xmlDoc.load("c:\books.xml")
Set root = xmldoc.documentElement
Set currNode = root.childNodes.item(2)
Set MyNewNode = currNode.cloneNode(true)
root.appendChild (MyNewNode)
MsgBox xmlDoc.xml

See Also

Applies To: XMLDOMAttribute Object | XMLDOMCDATASection Object | XMLDOMCharacterData Object | XMLDOMComment Object | DOMDocument Object | XMLDOMDocumentFragment Object Object | XMLDOMDocumentType Object | XMLDOMElement Object | XMLDOMEntity Object | XMLDOMEntityReference Object | XMLDOMNode Object | XMLDOMNotation Object | XMLDOMProcessingInstruction Object | XMLDOMText Object | XTLRuntime Object