
XML.insertBefore() Method
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
932
|
ActionScript Language Reference
The ignoreWhite property must be set before XML parsing occurs (typically due to a load()
or sendAndLoad() operation).
See Also
The manual whitespace-stripping code examples under the XML class entry
XML.insertBefore() Method
insert a new sibling node before an existing node
Flash 5
theNode.insertBefore(newChild, beforeChild)
Arguments
newChild An existing XML node object.
beforeChild The child of
theNode before which newChild should be inserted.
Description
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.
Example
// 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>"
See Also
XML.appendChild(), XML.previousSibling, XML.removeNode()