| XML.insertBefore( ) Method | Flash 5 |
| insert a new sibling node before an existing node |
An existing XML node object.
The child of theNode before which newChild should be inserted.
The insertBefore( ) method adds newChild to theNode's child list, before beforeChild (theNode can be an XML or XMLnode instance). The insertBefore( ) method is similar to appendChild( ), but it lets us position a new node precisely in an existing XML object hierarchy.
// Create a document with a P node
myDoc = new XML('<P>paragraph 2</P>');
// Create another P node and a text node
newP = myDoc.createElement("P");
newText = myDoc.createTextNode("paragraph 1");
// Append the text node to the new P node
newP.appendChild(newText);
// Insert the new P node (including its text child) before the existing P node
myDoc.insertBefore(newP, myDoc.firstChild);
trace(myDoc); // Displays: "<P>paragraph 1</P><P>paragraph 2</P>"
XML.appendChild( ) XML.previousSibling, XML.removeNode( )