User Guide
XMLNode 1319
The clone of the node that is returned is no longer associated with the tree of the cloned item.
Consequently,
nextSibling, parentNode, and previousSibling all have a value of null. If
the
deep parameter is set to false, or the my_xml node has no child nodes, firstChild and
lastChild are also null.
Availability: ActionScript 1.0; Flash Player 5
Parameters
deep:Boolean - A Boolean value; if set to true, the children of the specified XML object will
be recursively cloned.
Returns
XMLNode - An XMLNode Object.
Example
The following example shows how to use the
XML.cloneNode() method to create a copy of a
node:
// create a new XML document
var doc:XML = new XML();
// create a root node
var rootNode:XMLNode = doc.createElement("rootNode");
// create three child nodes
var oldest:XMLNode = doc.createElement("oldest");
var middle:XMLNode = doc.createElement("middle");
var youngest:XMLNode = doc.createElement("youngest");
// add the rootNode as the root of the XML document tree
doc.appendChild(rootNode);
// add each of the child nodes as children of rootNode
rootNode.appendChild(oldest);
rootNode.appendChild(middle);
rootNode.appendChild(youngest);
// create a copy of the middle node using cloneNode()
var middle2:XMLNode = middle.cloneNode(false);
// insert the clone node into rootNode between the middle and youngest nodes
rootNode.insertBefore(middle2, youngest);
trace(rootNode);
// output (with line breaks added):
// <rootNode>
// <oldest />