| Package | Top Level | 
| Class | public final dynamic class XML | 
| Inheritance | XML  Object | 
Use the toXMLString() method to return a string representation of the XML object
 regardless of whether the XML object has simple content or complex content.
Note: The XML class (along with related classes) from ActionScript 2.0 has been renamed XMLDocument and moved into the flash.xml package. It is included in ActionScript 3.0 for backward compatibility.
See also
| Property | Defined By | ||
|---|---|---|---|
|  | constructor : Object 
  A reference to the class object or constructor function for a given object instance. | Object | |
| ignoreComments : Boolean [static] 
 Determines whether XML comments are ignored 
 when XML objects parse the source XML data. | XML | ||
| ignoreProcessingInstructions : Boolean [static] 
 Determines whether XML 
 processing instructions are ignored when XML objects parse the source XML data. | XML | ||
| ignoreWhitespace : Boolean [static] 
 Determines whether white space characters
 at the beginning and end of text nodes are ignored during parsing. | XML | ||
| prettyIndent : int [static] 
 Determines the amount of indentation applied by 
 the toString() and toXMLString() methods when 
 the XML.prettyPrinting property is set to true. | XML | ||
| prettyPrinting : Boolean [static] 
 Determines whether the toString() 
 and toXMLString() methods normalize white space characters between some tags. | XML | ||
|  | prototype : Object [static] 
  A reference to the prototype object of a class or function object. | Object | |
| Method | Defined By | ||
|---|---|---|---|
|  
 Creates a new XML object. | XML | ||
| 
 Adds a namespace to the set of in-scope namespaces for the XML object. | XML | ||
| 
 Appends the given child to the end of the XML object's properties. | XML | ||
| 
 Returns the XML value of the attribute that has the name matching the attributeName
 parameter. | XML | ||
| 
 Returns a list of attribute values for the given XML object. | XML | ||
| 
 Lists the children of an XML object. | XML | ||
| 
 Identifies the zero-indexed position of this XML object within the context of its parent. | XML | ||
| 
 Lists the children of the XML object in the sequence in which they appear. | XML | ||
| 
 Lists the properties of the XML object that contain XML comments. | XML | ||
| 
 Compares the XML object against the given value parameter. | XML | ||
| 
 Returns a copy of the given XML object. | XML | ||
| [static] 
 Returns an object with the following properties set to the default values: ignoreComments, 
 ignoreProcessingInstructions, ignoreWhitespace, prettyIndent, and 
 prettyPrinting. | XML | ||
| 
 Returns all descendants (children, grandchildren, great-grandchildren, and so on) of the 
 XML object that have the given name parameter. | XML | ||
| 
  Lists the elements of an XML object. | XML | ||
| 
 Checks to see whether the XML object contains complex content. | XML | ||
| 
 Checks to see whether the object has the property specified by the p parameter. | XML | ||
| 
 Checks to see whether the XML object contains simple content. | XML | ||
| 
 Lists the namespaces for the XML object, based on the object's parent. | XML | ||
| 
 Inserts the given child2 parameter after the child1 parameter in this XML object and returns the 
 resulting object. | XML | ||
| 
 Inserts the given child2 parameter before the child1 parameter 
 in this XML object and returns the resulting object. | XML | ||
|  | 
  Indicates whether an instance of the Object class is in the prototype chain of the object specified 
  as the parameter. | Object | |
| 
 For XML objects, this method always returns the integer 1. | XML | ||
| 
 Gives the local name portion of the qualified name of the XML object. | XML | ||
| 
 Gives the qualified name for the XML object. | XML | ||
| 
 If no parameter is provided, gives the namespace associated with the qualified name of 
 this XML object. | XML | ||
| 
 Lists namespace declarations associated with the XML object in the context of its parent. | XML | ||
| 
 Specifies the type of node: text, comment, processing-instruction,  
 attribute, or element. | XML | ||
| 
 For the XML object and all descendant XML objects, merges adjacent text nodes and 
 eliminates empty text nodes. | XML | ||
| 
 Returns the parent of the XML object. | XML | ||
| 
 Inserts a copy of the provided child object into the XML element before any existing XML 
 properties for that element. | XML | ||
| 
 If a name parameter is provided, lists all the children of the XML object 
 that contain processing instructions with that name. | XML | ||
| 
 Checks whether the property p is in the set of properties that can be iterated in a 
 for..in statement applied to the XML object. | XML | ||
| 
 Removes the given namespace for this object and all descendants. | XML | ||
| 
 Replaces the properties specified by the propertyName parameter 
 with the given value parameter. | XML | ||
| 
 Replaces the child properties of the XML object with the specified set of XML properties, 
 provided in the value parameter. | XML | ||
| 
 Changes the local name of the XML object to the given name parameter. | XML | ||
| 
 Sets the name of the XML object to the given qualified name or attribute name. | XML | ||
| 
 Sets the namespace associated with the XML object. | XML | ||
|  | 
     Sets the availability of a dynamic property for loop operations. | Object | |
| [static] 
 Sets values for the following XML properties: ignoreComments, 
 ignoreProcessingInstructions, ignoreWhitespace,
 prettyIndent, and prettyPrinting. | XML | ||
| [static] 
 Retrieves the following properties: ignoreComments, 
 ignoreProcessingInstructions, ignoreWhitespace, 
 prettyIndent, and prettyPrinting. | XML | ||
| 
 Returns an XMLList object of all XML properties of the XML object that represent XML text nodes. | XML | ||
| 
 Returns a string representation of the XML object. | XML | ||
| 
 Returns a string representation of the XML object. | XML | ||
| 
 Returns the XML object. | XML | ||
| ignoreComments | property | 
ignoreComments:Boolean  [read-write] 
 Determines whether XML comments are ignored 
 when XML objects parse the source XML data. By default, the comments are ignored 
 (true). To include XML comments, set this property to false. 
 The ignoreComments property is used only during the XML parsing, not during 
 the call to any method such as myXMLObject.child(*).toXMLString(). 
 If the source XML includes comment nodes, they are kept or discarded during the XML parsing. 
  
    public static function get ignoreComments():Boolean
    public function set ignoreComments(value:Boolean):void
See also
XML.ignoreComments
 to false and to true:
XML.ignoreComments = false;
var xml1:XML = 
        <foo>
            <!-- comment -->
        </foo>;
trace(xml1.toXMLString()); // <foo><!-- comment --></foo>
XML.ignoreComments = true;
var xml2:XML = 
        <foo>
            <!-- example -->
        </foo>;
trace(xml2.toXMLString()); // <foo/>| ignoreProcessingInstructions | property | 
ignoreProcessingInstructions:Boolean  [read-write] 
 Determines whether XML 
 processing instructions are ignored when XML objects parse the source XML data. 
 By default, the processing instructions are ignored (true). To include XML 
 processing instructions, set this property to false. The 
 ignoreProcessingInstructions property is used only during the XML parsing, 
 not during the call to any method such as myXMLObject.child(*).toXMLString().
 If the source XML includes processing instructions nodes, they are kept or discarded during 
 the XML parsing.
  
    public static function get ignoreProcessingInstructions():Boolean
    public function set ignoreProcessingInstructions(value:Boolean):void
See also
XML.ignoreProcessingInstructions
 to false and to true:
XML.ignoreProcessingInstructions = false;
var xml1:XML = 
        <foo>
            <?exampleInstruction ?>
        </foo>;
trace(xml1.toXMLString()); // <foo><?exampleInstruction ?></foo>
XML.ignoreProcessingInstructions = true;
var xml2:XML = 
        <foo>
            <?exampleInstruction ?>
        </foo>;
trace(xml2.toXMLString()); // <foo/>| ignoreWhitespace | property | 
ignoreWhitespace:Boolean  [read-write] 
 Determines whether white space characters
 at the beginning and end of text nodes are ignored during parsing. By default, 
 white space is ignored (true). If a text node is 100% white space and the 
 ignoreWhitespace property is set to true, then the node is not created.  
 To show white space in a text node, set the ignoreWhitespace property to 
 false. 
  
    public static function get ignoreWhitespace():Boolean
    public function set ignoreWhitespace(value:Boolean):void
XML.ignoreWhitespace
 to false and to true:XML.ignoreWhitespace = false; var xml1:XML = <foo> </foo>; trace(xml1.children().length()); // 1 XML.ignoreWhitespace = true; var xml2:XML = <foo> </foo>; trace(xml2.children().length()); // 0
| prettyIndent | property | 
prettyIndent:int  [read-write] 
 Determines the amount of indentation applied by 
 the toString() and toXMLString() methods when 
 the XML.prettyPrinting property is set to true. 
 Indentation is applied with the space character, not the tab character.
 
 The default value is 2.
  
    public static function get prettyIndent():int
    public function set prettyIndent(value:int):void
See also
XML.prettyIndent
 static property:var xml:XML = <foo><bar/></foo>; XML.prettyIndent = 0; trace(xml.toXMLString()); XML.prettyIndent = 1; trace(xml.toXMLString()); XML.prettyIndent = 2; trace(xml.toXMLString());
| prettyPrinting | property | 
prettyPrinting:Boolean  [read-write] 
 Determines whether the toString() 
 and toXMLString() methods normalize white space characters between some tags. 
 The default value is true.
  
    public static function get prettyPrinting():Boolean
    public function set prettyPrinting(value:Boolean):void
See also
XML.prettyPrinting
 static property:var xml:XML = <foo><bar/></foo>; XML.prettyPrinting = false; trace(xml.toXMLString()); XML.prettyPrinting = true; trace(xml.toXMLString());
| XML | () | Constructor | 
public function XML(value:Object)
Creates a new XML object. You must use the constructor to create an XML object before you call any of the methods of the XML class.
Use the toXMLString() method to return a string representation of the XML object
 regardless of whether the XML object has simple content or complex content.
| value:Object— Any object that can be converted to XML with the top-levelXML()function. | 
See also
| addNamespace | () | method | 
AS3 function addNamespace(ns:Object):XML
 Adds a namespace to the set of in-scope namespaces for the XML object. If the namespace already 
 exists in the in-scope namespaces for the XML object (with a prefix matching that of the given 
 parameter), then the prefix of the existing namespace is set to undefined. If the input parameter 
 is a Namespace object, it's used directly. If it's a QName object, the input parameter's
 URI is used to create a new namespace; otherwise, it's converted to a String and a namespace is created from 
 the String.
  
Parameters
| ns:Object— The namespace to add to the XML object. | 
| XML— The new XML object, with the namespace added. | 
var xml1:XML = <ns:foo xmlns:ns="www.example.com/ns" />; var nsNamespace:Namespace = xml1.namespace(); var xml2:XML = <bar />; xml2.addNamespace(nsNamespace); trace(xml2.toXMLString()); // <bar xmlns:ns="www.example.com/ns"/>
| appendChild | () | method | 
AS3 function appendChild(child:Object):XML
 Appends the given child to the end of the XML object's properties.
 The appendChild() method takes an XML object, an XMLList object, or 
 any other data type that is then converted to a String. 
        
Use the delete (XML) operator to remove XML nodes.
Parameters
| child:Object— The XML object to append. | 
| XML— The resulting XML object. | 
See also
var xml:XML = 
        <body>
            <p>hello</p>
        </body>;
        
xml.appendChild(<p>world</p>);    
trace(xml.p[0].toXMLString()); // <p>hello</p>
trace(xml.p[1].toXMLString()); // <p>world</p>| attribute | () | method | 
AS3 function attribute(attributeName:*):XMLList
 Returns the XML value of the attribute that has the name matching the attributeName
 parameter. Attributes are found within XML elements. 
 In the following example, the element has an attribute named "gender" 
 with the value "boy": <first gender="boy">John</first>.
 
 
The attributeName parameter can be any data type; however, 
 String is the most common data type to use. When passing any object other than a QName object, 
 the attributeName parameter uses the toString() method
 to convert the parameter to a string. 
If you need a qualified name reference, you can pass in a QName object. A QName object
 defines a namespace and the local name, which you can use to define the qualified name of an 
 attribute. Therefore calling attribute(qname) is not the same as calling
 attribute(qname.toString()).
Parameters
| attributeName:*— The name of the attribute. | 
| XMLList— An XMLList object or an empty XMLList object. Returns an empty XMLList object
 when an attribute value has not been defined. | 
See also
attribute() method. The
 localName property is attr and the namespace property
 is ns.
var xml:XML = <ns:node xmlns:ns = "http://uri" ns:attr = '7' />       
var qn:QName = new QName("http://uri", "attr");
trace(xml.attribute(qn)); // 7attribute() method instead of the attribute identifier (@) 
 operator, as in the following example:
var xml:XML = <example class="first" />
trace(xml.attribute("class"));
 | attributes | () | method | 
AS3 function attributes():XMLList
 Returns a list of attribute values for the given XML object. Use the name() 
 method with the attributes() method to return the name of an attribute.
 Use @* to return the names of all attributes.
 
 
| XMLList— The list of attribute values. | 
See also
var xml:XML=<example id='123' color='blue'/> trace(xml.attributes()[1].name()); //color
 
var xml:XML = <example id='123' color='blue'/>
var attNamesList:XMLList = xml.@*;
trace(attNamesList is XMLList); // true
trace(attNamesList.length()); // 2
for (var i:int = 0; i < attNamesList.length(); i++)
{ 
    trace(typeof (attNamesList[i])); // xml
    trace(attNamesList[i].nodeKind()); // attribute
    trace(attNamesList[i].name()); // id and color
} 
| child | () | method | 
AS3 function child(propertyName:Object):XMLList
Lists the children of an XML object. An XML child is an XML element, text node, comment, or processing instruction.
Use the propertyName parameter to list the 
 contents of a specific XML child. For example, to return the contents of a child named 
 <first>, use child.name("first"). You can generate the same result 
 by using the child's index number. The index number identifies the child's position in the 
 list of other XML children. For example, name.child(0) returns the first child 
 in a list. 
Use an asterisk (*) to output all the children in an XML document. 
 For example, doc.child("*").
Use the length() method with the asterisk (*) parameter of the 
 child() method to output the total number of children. For example, 
 numChildren = doc.child("*").length().
Parameters
| propertyName:Object— The element name or integer of the XML child. | 
| XMLList— An XMLList object of child nodes that match the input parameter. | 
See also
child() method to identify child
 elements with a specified name:
var xml:XML = 
        <foo>
            <bar>text1</bar>
            <bar>text2</bar>
        </foo>;
trace(xml.child("bar").length());  // 2
trace(xml.child("bar")[0].toXMLString()); // <bar>text1</bar>
trace(xml.child("bar")[1].toXMLString()); // <bar>text2</bar>| childIndex | () | method | 
AS3 function childIndex():int
Identifies the zero-indexed position of this XML object within the context of its parent.
Returns| int— The position of the object. Returns -1 as well as positive integers. | 
childIndex() method:
var xml:XML = 
            <foo>
                <bar />
                text
                <bob />
            </foo>;
trace(xml.bar.childIndex()); // 0
trace(xml.bob.childIndex()); // 2| children | () | method | 
AS3 function children():XMLList
Lists the children of the XML object in the sequence in which they appear. An XML child is an XML element, text node, comment, or processing instruction.
Returns| XMLList— An XMLList object of the XML object's children. | 
children() method:
XML.ignoreComments = false;
XML.ignoreProcessingInstructions = false;
var xml:XML = 
        <foo id="22">
            <bar>44</bar>
            text
            <!-- comment -->
            <?instruction ?>
        </foo>;
trace(xml.children().length()); // 4
trace(xml.children()[0].toXMLString()); // <bar>44</bar>
trace(xml.children()[1].toXMLString()); // text
trace(xml.children()[2].toXMLString()); // <!-- comment -->
trace(xml.children()[3].toXMLString()); // <?instruction ?>| comments | () | method | 
AS3 function comments():XMLList
Lists the properties of the XML object that contain XML comments.
Returns| XMLList— An XMLList object of the properties that contain comments. | 
comments() method:
XML.ignoreComments = false;
var xml:XML = 
        <foo>
            <!-- example -->
            <!-- example2 -->
        </foo>;
trace(xml.comments().length()); // 2
trace(xml.comments()[1].toXMLString()); // <!-- example2 -->| contains | () | method | 
AS3 function contains(value:XML):Boolean
 Compares the XML object against the given value parameter. 
  
Parameters
| value:XML— A value to compare against the current XML object. | 
| Boolean— If the XML object matches thevalueparameter, thentrue; otherwisefalse. | 
contains() method:
var xml:XML = 
        <order>
            <item>Rice</item>
            <item>Kung Pao Shrimp</item>
        </order>;
trace(xml.item[0].contains(<item>Rice</item>)); // true
trace(xml.item[1].contains(<item>Kung Pao Shrimp</item>)); // true
trace(xml.item[1].contains(<item>MSG</item>)); // false| copy | () | method | 
AS3 function copy():XML
 Returns a copy of the given XML object. The copy is a duplicate of the entire tree of nodes. 
 The copied XML object has no parent and returns null if you attempt to call the 
 parent() method.
     
| XML— The copy of the object. | 
copy() method creates a new instance of an XML object. 
 When you modify the copy, the original remains unchanged:var xml1:XML = <foo />; var xml2:XML = xml1.copy(); xml2.appendChild(<bar />); trace(xml1.bar.length()); // 0 trace(xml2.bar.length()); // 1
| defaultSettings | () | method | 
AS3 static function defaultSettings():Object
 Returns an object with the following properties set to the default values: ignoreComments, 
 ignoreProcessingInstructions, ignoreWhitespace, prettyIndent, and 
 prettyPrinting. The default values are as follows:
  
ignoreComments = true
ignoreProcessingInstructions = true
ignoreWhitespace = true
prettyIndent = 2
prettyPrinting = true
Note: You do not apply this method to an instance of the XML class; you apply it to 
 XML, as in the following code: var df:Object = XML.defaultSettings(). 
| Object— An object with properties set to the default settings. | 
See also
XML.ignoreComments = false;
XML.ignoreProcessingInstructions = false;
var customSettings:Object = XML.settings();
var xml1:XML = 
        <foo>
            <!-- comment -->
            <?instruction ?>
        </foo>;
trace(xml1.toXMLString());
//    <foo>
//        <!-- comment -->
//         <?instruction ?>
//    </foo>
XML.setSettings(XML.defaultSettings());
var xml2:XML = 
        <foo>
            <!-- comment -->
            <?instruction ?>
        </foo>;
trace(xml2.toXMLString());
| descendants | () | method | 
AS3 function descendants(name:Object = *):XMLList
 Returns all descendants (children, grandchildren, great-grandchildren, and so on) of the 
 XML object that have the given name parameter. The name parameter
 is optional. The name parameter can be a QName object, a String data type
 or any other data type that is then converted to a String data type.
 
 
To return all descendants, use the "*" parameter. If no parameter is passed, the string "*" is passed and returns all descendants of the XML object.
Parameters
| name:Object(default =*)— The name of the element to match. | 
| XMLList— An XMLList object of matching descendants. If there are no descendants, returns an 
 empty XMLList object. | 
See also
descendants() method instead of the descendant (..) operator, as in the 
 following example: 
var xml:XML = 
  <enrollees>
    <student id="239">
        <class name="Algebra" />
        <class name="Spanish 2"/>
    </student>
    <student id="206">
        <class name="Trigonometry" />
        <class name="Spanish 2" />
    </student>
  </enrollees>
trace(xml.descendants("class")); descendants() method returns an XMLList object
 that contains all descendant objects, including children, grandchildren, and so on:
XML.ignoreComments = false;
var xml:XML = 
        <body>
            <!-- comment -->
            text1
            <a>
                <b>text2</b>
            </a>
        </body>;
trace(xml.descendants("*").length()); // 5
trace(xml.descendants("*")[0]); // // <!-- comment -->
trace(xml.descendants("*")[1].toXMLString()); // text1
trace(xml.descendants("a").toXMLString()); // <a><b>text2</b></a>
trace(xml.descendants("b").toXMLString()); // <b>text2</b>| elements | () | method | 
AS3 function elements(name:Object = *):XMLList
  Lists the elements of an XML object. An element consists of a start and an end tag; 
  for example <first></first>. The name parameter 
  is optional. The name parameter can be a QName object, a String data type,
  or any other data type that is then converted to a String data type. Use the name parameter to list a specific element. For example, 
  the element "first" returns "John" in this example: 
  <first>John</first>. 
  
  
To list all elements, use the asterisk (*) as the parameter. The asterisk is also the default parameter.
Use the length() method with the asterisk parameter to output the total 
  number of elements. For example, numElement = addressbook.elements("*").length().
Parameters
| name:Object(default =*)— The name of the element. An element's name is surrounded by angle brackets. 
  For example, "first" is thenamein this example:<first></first>. | 
| XMLList— An XMLList object of the element's content. The element's content falls between the start and 
  end tags. If you use the asterisk (*) to call all elements, both the 
  element's tags and content are returned. | 
See also
elements() method returns a 
 list of elements only
 — not comments, text properties, or processing instructions:
var xml:XML = 
        <foo>
            <!-- comment -->
            <?instruction ?>
            text
            <a>1</a>
            <b>2</b>
        </foo>;
trace(xml.elements("*").length()); // 2
trace(xml.elements("*")[0].toXMLString()); // <a>1</a>
trace(xml.elements("b").length()); // 1
trace(xml.elements("b")[0].toXMLString()); // <b>2</b>
elements() method instead of the XML dot (.) operator, 
 as in the following example:
var xml:XML =
 <student id="206">
    <class name="Trigonometry" />
    <class name="Spanish 2" />
 </student>
trace(xml.elements("class")); 
| hasComplexContent | () | method | 
AS3 function hasComplexContent():Boolean
Checks to see whether the XML object contains complex content. An XML object contains complex content if it has child elements. XML objects that representing attributes, comments, processing instructions, and text nodes do not have complex content. However, an object that contains these can still be considered to contain complex content (if the object has child elements).
Returns| Boolean— If the XML object contains complex content,true; otherwisefalse. | 
See also
a that has
 simple content and one property named a that has complex content:
var xml:XML = 
        <foo>
            <a>
                text
            </a>
            <a>
                <b/>
            </a>
        </foo>;
trace(xml.a[0].hasComplexContent()); // false
trace(xml.a[1].hasComplexContent()); // true
trace(xml.a[0].hasSimpleContent()); // true
trace(xml.a[1].hasSimpleContent()); // false| hasOwnProperty | () | method | 
AS3 function hasOwnProperty(p:String):Boolean
 Checks to see whether the object has the property specified by the p parameter. 
  
Parameters
| p:String— The property to match. | 
| Boolean— If the property exists,true; otherwisefalse. | 
hasOwnProperty() method to ensure
 that a property (b) exists prior to evaluating an expression (b == "11") that uses the
 property:
var xml:XML = 
        <foo>
            <a />
            <a>
                <b>10</b>
            </a>
            <a>
                <b>11</b>
            </a>
        </foo>;
trace(xml.a.(hasOwnProperty("b") && b == "11")); a does not have a property named b:
 
trace(xml.a.(b == "11"));
hasOwnProperty() method to ensure
 that a property (item) exists prior to evaluating an expression 
 (item.contains("toothbrush")) that uses the
 property:
var xml:XML = 
        <orders>
            <order id='1'>
                <item>toothbrush</item>
                <item>toothpaste</item>
            </order>
            <order>
                <returnItem>shoe polish</returnItem>
            </order>
        </orders>;
trace(xml.order.(hasOwnProperty("item") && item.contains("toothbrush"))); | hasSimpleContent | () | method | 
AS3 function hasSimpleContent():Boolean
Checks to see whether the XML object contains simple content. An XML object contains simple content if it represents a text node, an attribute node, or an XML element that has no child elements. XML objects that represent comments and processing instructions do not contain simple content.
Returns| Boolean— If the XML object contains simple content,true; otherwisefalse. | 
See also
a that has
 simple content and one property named a that has complex content:
var xml:XML = 
        <foo>
            <a>
                text
            </a>
            <a>
                <b/>
            </a>
        </foo>;
trace(xml.a[0].hasComplexContent()); // false
trace(xml.a[1].hasComplexContent()); // true
trace(xml.a[0].hasSimpleContent()); // true
trace(xml.a[1].hasSimpleContent()); // false| inScopeNamespaces | () | method | 
AS3 function inScopeNamespaces():Array
Lists the namespaces for the XML object, based on the object's parent.
Returns| Array— An array of Namespace objects. | 
| insertChildAfter | () | method | 
AS3 function insertChildAfter(child1:Object, child2:Object):*
 Inserts the given child2 parameter after the child1 parameter in this XML object and returns the 
 resulting object. If the child1 parameter is null, the method
 inserts the contents of child2
before all children of the XML object 
 (in other words, after none). If child1 is provided, but it does not 
 exist in the XML object, the XML object is not modified and undefined is 
 returned.
 
 
If you call this method on an XML child that is not an element (text, attributes, comments, pi, and so on) 
 undefined is returned.
Use the delete (XML) operator to remove XML nodes.
Parameters
| child1:Object— The object in the source object that you insert beforechild2. | |
| child2:Object— The object to insert. | 
| *— The resulting XML object orundefined. | 
See also
var xml:XML = 
        <menu>
            <item>burger</item>
            <item>soda</item>
        </menu>;
xml.insertChildAfter(xml.item[0], <saleItem>fries</saleItem>);
trace(xml);trace() output is the following:
 
 <menu>
 	<item>burger</item>
 	<saleItem>fries</saleItem>
 	<item>soda</item>
 </menu>
| insertChildBefore | () | method | 
AS3 function insertChildBefore(child1:Object, child2:Object):*
 Inserts the given child2 parameter before the child1 parameter 
 in this XML object and returns the resulting object. If the child1 parameter 
 is null, the method inserts the contents of    
 child2
after all children of the XML object (in other words, before 
 none). If child1 is provided, but it does not exist in the XML object, 
 the XML object is not modified and undefined is returned.
 
 
If you call this method on an XML child that is not an element (text, attributes, 
 comments, pi, and so on) undefined is returned.
Use the delete (XML) operator to remove XML nodes.
Parameters
| child1:Object— The object in the source object that you insert afterchild2. | |
| child2:Object— The object to insert. | 
| *— The resulting XML object orundefined. | 
See also
var xml:XML = 
        <menu>
            <item>burger</item>
            <item>soda</item>
        </menu>;
xml.insertChildBefore(xml.bar[0], <saleItem>fries</saleItem>);
trace(xml);trace() output is the following:
 
<menu>
 	<saleItem>fries</saleItem>
 	<item>burger</item>
 	<item>soda</item>
 </menu>
| length | () | method | 
AS3 function length():int
 For XML objects, this method always returns the integer 1. 
 The length() method of the XMLList class returns a value of 1 for 
 an XMLList object that contains only one value.
  
| int— Always returns1for any XML object. | 
| localName | () | method | 
AS3 function localName():Object
Gives the local name portion of the qualified name of the XML object.
Returns| Object— The local name as either a String ornull. | 
localName() method:
var xml:XML = 
        <soap:Envelope xmlns:soap="http://www.w3.org/2001/12/soap-envelope"
            soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding">
                        <soap:Body xmlns:wx = "http://example.com/weather">
                <wx:forecast>
                    <wx:city>Quito</wx:city>
                </wx:forecast>
            </soap:Body>
        </soap:Envelope>;
        
trace(xml.localName()); // Envelope| name | () | method | 
AS3 function name():Object
Gives the qualified name for the XML object.
Returns| Object— The qualified name is either a QName ornull. | 
See also
name() method to get the qualified
 name of an XML object:
var xml:XML = 
        <soap:Envelope xmlns:soap="http://www.w3.org/2001/12/soap-envelope"
            soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding">
                        <soap:Body xmlns:wx = "http://example.com/weather">
                <wx:forecast>
                    <wx:city>Quito</wx:city>
                </wx:forecast>
            </soap:Body>
        </soap:Envelope>;
        
trace(xml.name().localName); // Envelope
trace(xml.name().uri); // "http://www.w3.org/2001/12/soap-envelope"name() method called on an XML property,
 on a text element, and on an attribute:
var xml:XML = 
        <foo x="15" y="22">
            text
        </foo>;
        
trace(xml.name().localName); // foo
trace(xml.name().uri == ""); // true
trace(xml.children()[0]); // text
trace(xml.children()[0].name()); // null
trace(xml.attributes()[0]); // 15
trace(xml.attributes()[0].name()); // x| namespace | () | method | 
AS3 function namespace(prefix:String = null):*
 If no parameter is provided, gives the namespace associated with the qualified name of 
 this XML object. If a prefix parameter is specified, the method returns the namespace 
 that matches the prefix parameter and that is in scope for the XML object. If there is no 
 such namespace, the method returns undefined.
  
Parameters
| prefix:String(default =null)— The prefix you want to match. | 
| *— Returnsnull,undefined, or a namespace. | 
namespace() method 
 to get the namespace of an XML object and assign it to a Namespace object named soap
 which is then used in identifying a property of the xml object 
 (xml.soap::Body[0]):
var xml:XML = 
        <soap:Envelope xmlns:soap="http://www.w3.org/2001/12/soap-envelope"
            soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding">
                        <soap:Body xmlns:wx = "http://example.com/weather">
                <wx:forecast>
                    <wx:city>Quito</wx:city>
                </wx:forecast>
            </soap:Body>
        </soap:Envelope>;
        
var soap:Namespace = xml.namespace();
trace(soap.prefix); // soap
trace(soap.uri); // http://www.w3.org/2001/12/soap-envelope
var body:XML = xml.soap::Body[0];
trace(body.namespace().prefix); // soap
trace(xml.namespace().uri); // http://www.w3.org/2001/12/soap-envelope
trace(body.namespace("wx").uri); // "http://example.com/weather"namespace() method to get the 
 default namespace for a node, as well as the namespace for a specific prefix ("dc"):
var xml:XML = 
        <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" 
            xmlns:dc="http://purl.org/dc/elements/1.1/" 
            xmlns="http://purl.org/rss/1.0/">
                <!-- ... -->
        </rdf:RDF>;
                    
trace(xml.namespace()); // http://www.w3.org/1999/02/22-rdf-syntax-ns#
trace(xml.namespace("dc")); // http://purl.org/dc/elements/1.1/
trace(xml.namespace("foo")); // undefined| namespaceDeclarations | () | method | 
AS3 function namespaceDeclarations():Array
Lists namespace declarations associated with the XML object in the context of its parent.
Returns| Array— An array of Namespace objects. | 
See also
var xml:XML = 
        <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" 
            xmlns:dc="http://purl.org/dc/elements/1.1/" 
            xmlns="http://purl.org/rss/1.0/">
            <!-- ... -->
            
        </rdf:RDF>;
                    
for (var i:uint = 0; i < xml.namespaceDeclarations().length; i++) {
    var ns:Namespace = xml.namespaceDeclarations()[i]; 
    var prefix:String = ns.prefix;
    if (prefix == "") {
        prefix = "(default)";
    }
    trace(prefix + ":" , ns.uri);
}trace() output is the following:
 
rdf: http://www.w3.org/1999/02/22-rdf-syntax-ns#
 dc: http://purl.org/dc/elements/1.1/
 (default): http://purl.org/rss/1.0/
| nodeKind | () | method | 
AS3 function nodeKind():String
Specifies the type of node: text, comment, processing-instruction, attribute, or element.
Returns| String— The node type used. | 
See also
XML.ignoreComments = false;
XML.ignoreProcessingInstructions = false;
var xml:XML = 
    <example id="10">
        <!-- this is a comment -->
        <?test this is a pi ?>
        and some text
    </example>;
trace(xml.nodeKind()); // element
trace(xml.children()[0].nodeKind()); // comment
trace(xml.children()[1].nodeKind()); // processing-instruction
trace(xml.children()[2].nodeKind()); // text
trace(xml.@id[0].nodeKind()); // attribute
| normalize | () | method | 
AS3 function normalize():XML
For the XML object and all descendant XML objects, merges adjacent text nodes and eliminates empty text nodes.
Returns| XML— The resulting normalized XML object. | 
normalize() method:
var xml:XML = <body></body>;
xml.appendChild("hello");
xml.appendChild(" world");
trace(xml.children().length()); // 2
xml.normalize();
trace(xml.children().length()); // 1| parent | () | method | 
AS3 function parent():*
 Returns the parent of the XML object. If the XML object has no parent, the method returns 
 undefined.
  
| *— The parent XML object. Returns either aStringornull. | 
parent() method to identify the parent element
 of a specific element in an XML structure:
var xml:XML = 
    <body>
        <p id="p1">Hello</p>
        <p id="p2">Test:
            <ul>
                <li>1</li>
                <li>2</li>
            </ul>
        </p>
    </body>;
var node:XML = xml.p.ul.(li.contains("1"))[0]; // == <ul> ... </ul>
trace(node.parent().@id); // p2| prependChild | () | method | 
AS3 function prependChild(value:Object):XML
 Inserts a copy of the provided child object into the XML element before any existing XML 
 properties for that element.
        
Use the delete (XML) operator to remove XML nodes.
Parameters
| value:Object— The object to insert. | 
| XML— The resulting XML object. | 
See also
prependChild() method to add an element to the 
 begining of a child list of an XML object:
var xml:XML = 
        <body>
            <p>hello</p>
        </body>;
        
xml.prependChild(<p>world</p>);    
trace(xml.p[0].toXMLString()); // <p>world</p>
trace(xml.p[1].toXMLString()); // <p>hello</p>| processingInstructions | () | method | 
AS3 function processingInstructions(name:String = "*"):XMLList
 If a name parameter is provided, lists all the children of the XML object 
 that contain processing instructions with that name. With no parameters, the method 
 lists all the children of the XML object that contain any processing instructions.
  
Parameters
| name:String(default = "*")— The name of the processing instructions to match. | 
| XMLList— A list of matching child objects. | 
processingInstructions() method to get an
 array of processing instructions for an XML object:
XML.ignoreProcessingInstructions = false;
var xml:XML =
    <body>
            foo
            <?xml-stylesheet href="headlines.css" type="text/css" ?>
            <?instructionX ?>
            
    </body>;
trace(xml.processingInstructions().length()); // 2
trace(xml.processingInstructions()[0].name()); // xml-stylesheet| propertyIsEnumerable | () | method | 
AS3 function propertyIsEnumerable(p:String):Boolean
 Checks whether the property p is in the set of properties that can be iterated in a 
 for..in statement applied to the XML object. Returns true only 
 if toString(p) == "0". 
  
Parameters
| p:String— The property that you want to check. | 
| Boolean—  If the property can be iterated in afor..instatement,true; 
 otherwise,false. | 
propertyNameIsEnumerable() method returns a value of 
 true only for the value 0; whereas for an 
 XMLList object, the return value is true for each valid index 
 value for the XMLList object:
var xml:XML = 
        <body>
             <p>Hello</p>
               <p>World</p>
        </body>;
trace(xml.propertyIsEnumerable(0)); // true
trace(xml.propertyIsEnumerable(1)); // false
for (var propertyName:String in xml) {
    trace(xml[propertyName]);
}
var list:XMLList = xml.p;
trace(list.propertyIsEnumerable(0)); // true
trace(list.propertyIsEnumerable(1)); // true
trace(list.propertyIsEnumerable(2)); // false
for (var propertyName:String in list) { 
    trace(list[propertyName]);
}| removeNamespace | () | method | 
AS3 function removeNamespace(ns:Namespace):XML
 Removes the given namespace for this object and all descendants. The removeNamespace() 
 method does not remove a namespace if it is referenced by the object's qualified name or the 
 qualified name of the object's attributes.
  
Parameters
| ns:Namespace— The namespace to remove. | 
| XML— A copy of the resulting XML object. | 
var xml:XML = 
    <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" 
        xmlns:dc="http://purl.org/dc/elements/1.1/" 
        xmlns="http://purl.org/rss/1.0/">
    
        <!-- ... -->
        
    </rdf:RDF>;
trace(xml.namespaceDeclarations().length); // 3
trace(xml.namespaceDeclarations()[0] is String); // 
var dc:Namespace = xml.namespace("dc");
xml.removeNamespace(dc);
trace(xml.namespaceDeclarations().length); // 2| replace | () | method | 
AS3 function replace(propertyName:Object, value:XML):XML
 Replaces the properties specified by the propertyName parameter 
 with the given value parameter. 
 If no properties match propertyName, the XML object is left unmodified.
 
 
Parameters
| propertyName:Object— Can be a 
 numeric value, an unqualified name for a set of XML elements, a qualified name for a set of 
 XML elements, or the asterisk wildcard ("*"). 
 Use an unqualified name to identify XML elements in the default namespace. | |
| value:XML— The replacement value. This can be an XML object, an XMLList object, or any value 
 that can be converted withtoString(). | 
| XML—  The resulting XML object, with the matching properties replaced. | 
replace() method
 with an integer as the first parameter:
var xml:XML = 
    <body>
        <p>Hello</p>
        <p>World</p>
        <hr/>
    </body>;
xml.replace(1, <p>Bob</p>);
trace(xml);trace() output:
 
 <body>
 	<p>Hello</p>
 	<p>Bob</p>
 	<hr/>
 </body>
 
replace() method
 with a string as the first parameter:
var xml:XML = 
    <body>
        <p>Hello</p>
        <p>World</p>
        <hr/>
    </body>;
xml.replace("p", <p>Hi</p>); 
trace(xml);trace() output:
 
 
 <body>
 	<p>Hi</p>
 	<hr/>
 </body>;
 
replace() method
 with a QName as the first parameter:
var xml:XML = 
    <ns:body xmlns:ns = "myNS">
        <ns:p>Hello</ns:p>
        <ns:p>World</ns:p>
        <hr/>
    </ns:body>;
var qname:QName = new QName("myNS", "p");
xml.replace(qname, <p>Bob</p>);
trace(xml);
trace() output:
 
 
 <ns:body xmlns:ns = "myNS">
 	<p>Bob</p>
 	<hr/>
 </ns:body>
 
replace() method
 with the string "*" as the first parameter:
var xml:XML = 
    <body>
        <p>Hello</p>
        <p>World</p>
        <hr/>
    </body>;
xml.replace("*", <img src = "hello.jpg"/>);
trace(xml);trace() output:
 
 
 <body>
 	<img src="hello.jpg"/>
 </body>
 
| setChildren | () | method | 
AS3 function setChildren(value:Object):XML
 Replaces the child properties of the XML object with the specified set of XML properties, 
 provided in the value parameter.
  
Parameters
| value:Object— The replacement XML properties. Can be a single XML object or an XMLList object. | 
| XML— The resulting XML object. | 
setChildren() method, first
 using an XML object as the parameter, and then using an XMLList object as the parameter:
var xml:XML = 
    <body>
        <p>Hello</p>
        <p>World</p>
    </body>;
var list:XMLList = xml.p;
xml.setChildren(<p>hello</p>);
trace(xml);
//    <body>
//        <p>hello</p>
//    </body>
xml.setChildren(list);
trace(xml);
//    <body>
//        <p>Hello</p>
//        <p>World</p>
//    </body>| setLocalName | () | method | 
AS3 function setLocalName(name:String):void
 Changes the local name of the XML object to the given name parameter. 
  
Parameters
| name:String— The replacement name for the local name. | 
setLocalName() method
 to change the local name of an XML element:
var xml:XML = 
    <ns:item xmlns:ns="http://example.com">
        toothbrush
    </ns:item>;
    
xml.setLocalName("orderItem");
trace(xml.toXMLString()); // <ns:orderItem xmlns:ns="http://example.com">toothbrush</ns:orderItem>| setName | () | method | 
AS3 function setName(name:String):void
Sets the name of the XML object to the given qualified name or attribute name.
Parameters
| name:String— The new name for the object. | 
setName() method
 to change the name of an XML element:
var xml:XML = 
    <item>
        toothbrush
    </item>;
    
xml.setName("orderItem");
trace(xml.toXMLString()); // <orderItem>toothbrush</orderItem>| setNamespace | () | method | 
AS3 function setNamespace(ns:Namespace):void
Sets the namespace associated with the XML object.
Parameters
| ns:Namespace— The new namespace. | 
soap namespace defined in one XML object 
 and applies it to the namespace of another XML object (xml2):
var xml1:XML = 
        <soap:Envelope xmlns:soap="http://www.w3.org/2001/12/soap-envelope"
            soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding">
            <!-- ... -->
        </soap:Envelope>;
var ns:Namespace = xml1.namespace("soap");
var xml2:XML = 
    <Envelope>
        <Body/>
    </Envelope>;
    
xml2.setNamespace(ns);
trace(xml2);| setSettings | () | method | 
AS3 static function setSettings(... rest):void
 Sets values for the following XML properties: ignoreComments, 
 ignoreProcessingInstructions, ignoreWhitespace,
 prettyIndent, and prettyPrinting.
 
 The following are the default settings, which are applied if no setObj parameter
 is provided:
  
XML.ignoreComments = true
XML.ignoreProcessingInstructions = true
XML.ignoreWhitespace = true
XML.prettyIndent = 2
XML.prettyPrinting = true
Note: You do not apply this method to an instance of the XML class; you apply it to 
 XML, as in the following code: XML.setSettings().
Parameters
| ... rest— An object with each of the following properties:
 | 
See also
XML.ignoreComments = false;
XML.ignoreProcessingInstructions = false;
var customSettings:Object = XML.settings();
var xml1:XML = 
        <foo>
            <!-- comment -->
            <?instruction ?>
        </foo>;
trace(xml1.toXMLString());
//    <foo>
//        <!-- comment -->
//         <?instruction ?>
//    </foo>
XML.setSettings(XML.defaultSettings());
var xml2:XML = 
        <foo>
            <!-- comment -->
            <?instruction ?>
        </foo>;
trace(xml2.toXMLString());
| settings | () | method | 
AS3 static function settings():Object
 Retrieves the following properties: ignoreComments, 
 ignoreProcessingInstructions, ignoreWhitespace, 
 prettyIndent, and prettyPrinting.
  
| Object— An object with the following XML properties:
 | 
See also
XML.ignoreComments = false;
XML.ignoreProcessingInstructions = false;
var customSettings:Object = XML.settings();
var xml1:XML = 
        <foo>
            <!-- comment -->
            <?instruction ?>
        </foo>;
trace(xml1.toXMLString());
//    <foo>
//        <!-- comment -->
//         <?instruction ?>
//    </foo>
XML.setSettings(XML.defaultSettings());
var xml2:XML = 
        <foo>
            <!-- comment -->
            <?instruction ?>
        </foo>;
trace(xml2.toXMLString());
| text | () | method | 
AS3 function text():XMLList
Returns an XMLList object of all XML properties of the XML object that represent XML text nodes.
Returns| XMLList— The list of properties. | 
text() method to get the text nodes of 
 an XML object:
var xml:XML =
        <body>
            text1
            <hr/>
            text2
        </body>;
trace(xml.text()[0]); // text1
trace(xml.text()[1]); // text2| toString | () | method | 
AS3 function toString():String
Returns a string representation of the XML object. The rules for this conversion depend on whether the XML object has simple content or complex content:
toString() returns the String contents of the 
 XML object with  the following stripped out: the start tag, attributes, namespace declarations, and 
 end tag.toString() returns an XML encoded String 
 representing the entire XML object, including the start tag, attributes, namespace declarations, 
 and end tag.To return the entire XML object every time, use toXMLString().
| String— The string representation of the XML object. | 
See also
toString() method returns when the 
 XML object has simple content:
var test:XML = <type name="Joe">example</type>; trace(test.toString()); //example
toString() method returns when the 
 XML object has complex content:
var test:XML = 
<type name="Joe">
    <base name="Bob"></base>
    example
</type>;
trace(test.toString());
  // <type name="Joe">
  // <base name="Bob"/>
  // example
  // </type> 
| toXMLString | () | method | 
AS3 function toXMLString():String
 Returns a string representation of the XML object. Unlike the toString() method,
 the toXMLString() method always returns the start tag, attributes,
 and end tag of the XML object, regardless of whether the XML object has simple content or complex 
 content. (The toString() method strips out these items for XML objects that contain 
 simple content.)
 
 
| String— The string representation of the XML object. | 
See also
toString() method 
 (which is applied to all parameters of a trace() method, by default) and using the
 toXMLString() method:
var xml:XML =
        <p>hello</p>;
trace(xml); // hello
trace(xml.toXMLString()); // <p>hello</p>| valueOf | () | method | 
AS3 function valueOf():XML
Returns the XML object.
Returns| XML— The primitive value of an XML instance. | 
valueOf() method
 is the same as the source XML object:
var xml:XML = <p>hello</p>; trace(xml.valueOf() === xml); // true
@) symbol is used in several of the trace() calls to locate information
 by attribute name.
package {
    import flash.display.Sprite;
    public class XmlExample extends Sprite {        
        public function XmlExample() {
            var employees:XML =
                <employees>
                    <employee ssn="123-123-1234">
                        <name first="John" last="Doe"/>
                        <address>
                            <street>11 Main St.</street>
                            <city>San Francisco</city>
                            <state>CA</state>
                            <zip>98765</zip>
                        </address>
                    </employee>
                    <employee ssn="789-789-7890">
                        <name first="Mary" last="Roe"/>
                        <address>
                            <street>99 Broad St.</street>
                            <city>Newton</city>
                            <state>MA</state>
                            <zip>01234</zip>
                        </address>
                    </employee>
                </employees>;
            trace(employees.employee[0].address.zip);   // 98765
            trace(employees.employee[1].@ssn);          // 789-789-7890
            trace(employees.employee.name);             // <name first="John" last="Doe"/>
                                                        // <name first="Mary" last="Roe"/>
            trace(employees..zip[0]);                   // 98765
            trace(employees..@ssn[1]);                  // 789-789-7890
            trace(employees..name);                     // <name first="John" last="Doe"/>
                                                        // <name first="Mary" last="Roe"/>
            trace(employees.employee[0].address.*);     // <street>11 Main St.</street>    
                                                        // <city>San Francisco</city>
                                                        // <state>CA</state>
                                                        // <zip>98765</zip>
            var node:String = "zip";
            trace(employees.employee[0].address[node]); // 98765
            
            var attribute:String = "ssn";
            trace(employees.employee[1].@[attribute]);  // 789-789-7890
            
            for each (var num:XML in employees..@ssn) {
                trace(num);                             // 123-123-1234
            }                                           // 789-789-7890
            
            var ssnToFind:String = "789-789-7890";
            trace(employees.employee.(@ssn == ssnToFind).toXMLString());
                                                        // <employee ssn="789-789-7890">
                                                        // <name first="Mary" last="Roe"/>
                                                        // <address>
                                                        // <street>99 Broad St.</street>
                                                        // <city>Newton</city>
                                                        // <state>MA</state>
                                                        // <zip>01234</zip>
                                                        // </address>
                                                        // </employee>
        }
    }
}