| Package | Top Level |
| Class | public final dynamic class XMLList |
| Inheritance | XMLList Object |
An XMLList object with one XML element is treated the same as an XML object. When there is one XML element, all methods that are available for the XML object are also available for the XMLList object.
In the following example, example.two is an XMLList object of length 1,
so you can call any XML method on it.
var example2 = <example><two>2</two></example>;
The following table lists the XML methods that are not included in the XMLList class, but which you can use when your XMLList object has only one XML element. If you attempt to use these methods with anything other than one XML element (zero or more than one element), an exception is thrown.
| XML methods |
|---|
addNamespace() |
appendChild() |
childIndex() |
inScopeNamespace() |
insertChildAFter() |
insertChildBefore() |
name() |
namespace() |
localName() |
namespaceDeclarations() |
nodeKind() |
prependChild() |
removeNamespace() |
replace() |
setChildren() |
setLocalName() |
setName() |
setNamespace() |
This class (along with the XML, Namespace, and QName classes) implements powerful XML-handling standards defined in ECMAScript for XML (E4X) specification (ECMA-357 edition 2).
View the examples. See also| XML, Namespace, QName |
| Function | Defined by | ||
|---|---|---|---|
|
Creates a new XMLList object.
| XMLList | ||
|
Calls the
attribute() method of each XML object and returns an XMLList object
of the results. | XMLList | ||
|
Calls the
attributes() method of each XML object and
returns an XMLList object of attributes for each XML object. | XMLList | ||
|
Calls the
child() method of each XML object and returns an XMLList object that
contains the results in order. | XMLList | ||
|
Calls the
children() method of each XML object and
returns an XMLList object that contains the results. | XMLList | ||
|
Calls the
comments() method of each XML object and returns
an XMLList of comments. | XMLList | ||
|
Checks whether the XMLList object contains an XML object that is equal to the given
value parameter. | XMLList | ||
|
Returns a copy of the given XMLList object.
| XMLList | ||
|
Returns all descendants (children, grandchildren, great-grandchildren, and so on) of the XML object
that have the given
name parameter. | XMLList | ||
|
Calls the
elements() method of each XML object. | XMLList | ||
|
Checks whether the XMLList object contains complex content.
| XMLList | ||
|
Checks for the property specified by
p. | XMLList | ||
|
Checks whether the XMLList object contains simple content.
| XMLList | ||
![]() |
Indicates whether an instance of the Object class is in the prototype chain of the object specified
as the parameter.
| Object | |
|
Returns the number of properties in the XMLList object.
| XMLList | ||
|
Merges adjacent text nodes and eliminates empty text nodes for each
of the following: all text nodes in the XMLList, all the XML objects
contained in the XMLList, and the descendants of all the XML objects in
the XMLList.
| XMLList | ||
|
Returns the parent of the XMLList object if all items in the XMLList object have the same parent.
| XMLList | ||
|
If a
name parameter is provided, lists all the children of the XMLList object that
contain processing instructions with that name. | XMLList | ||
|
Checks whether the property
p is in the set of properties that can be iterated in a for..in statement
applied to the XMLList object. | XMLList | ||
![]() |
Sets the availability of a dynamic property for loop operations.
| Object | |
|
Calls the
text() method of each XML
object and returns an XMLList object that contains the results. | XMLList | ||
|
Returns a string representation of all the XML objects in an XMLList object.
| XMLList | ||
|
Returns a string representation of all the XML objects in an XMLList object.
| XMLList | ||
|
Returns the XMLList object.
| XMLList | ||
public function XMLList(value:Object)
value:Object — Any object that can be converted to an XMLList object by using the top-level XMLList() function.
|
| top-level XMLList() function |
public function attribute(attributeName:*):XMLList
attribute() method of each XML object and returns an XMLList object
of the results. The results match the given attributeName parameter. If there is no
match, the attribute() method returns an empty XMLList object.
Parameters
attributeName:* — The name of the attribute that you want to include in an XMLList object.
|
XMLList —
An XMLList object of matching XML objects or an empty XMLList object.
|
| XML.attribute(), XML.attributes() |
public function attributes():XMLList
attributes() method of each XML object and
returns an XMLList object of attributes for each XML object.
Returns
XMLList —
An XMLList object of attributes for each XML object.
|
| XML.attribute(), XML.attributes() |
public function child(propertyName:Object):XMLList
child() method of each XML object and returns an XMLList object that
contains the results in order.
Parameters
propertyName:Object — The element name or integer of the XML child.
|
XMLList —
An XMLList object of child nodes that match the input parameter.
|
| XML.child() |
public function children():XMLList
children() method of each XML object and
returns an XMLList object that contains the results.
Returns
XMLList —
An XMLList object of the children in the XML objects.
|
| XML.children() |
public function comments():XMLList
comments() method of each XML object and returns
an XMLList of comments.
Returns
XMLList —
An XMLList of the comments in the XML objects.
|
| XML.comments() |
public function contains(value:XML):Boolean
value parameter.
Parameters
value:XML — An XML object to compare against the current XMLList object.
|
Boolean —
If the XMLList contains the XML object declared in the value parameter,
then true; otherwise false.
|
public function copy():XMLList
null if you attempt to call the parent() method.
Returns
XMLList —
The copy of the XMLList object.
|
public function descendants(name:Object = *):XMLList
name parameter. 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 asterisk (*) parameter. If no parameter is passed, the string "*" is passed and returns all descendants of the XML object.
Parametersname:Object (default = *) — The name of the element to match.
|
XMLList —
An XMLList object of the matching descendants (children, grandchildren, and so on) of the XML objects
in the original list. If there are no descendants, returns an empty XMLList object.
|
| XML.descendants() |
public function elements(name:Object = *):XMLList
elements() method of each XML object. The name parameter is
passed to the descendants() method. If no parameter is passed, the string "*" is passed to the
descendants() method.
Parameters
name:Object (default = *) — The name of the elements to match.
|
XMLList —
An XMLList object of the matching child elements of the XML objects.
|
| XML.elements() |
public function hasComplexContent():Boolean
Boolean —
If the XMLList object contains complex content, then true; otherwise false.
|
| XML.hasComplexContent(), XML.hasSimpleContent(), hasSimpleContent() |
public function hasOwnProperty(p:String):Boolean
p.
Parameters
p:String — The property to match.
|
Boolean —
If the parameter exists, then true; otherwise false.
|
public function hasSimpleContent():Boolean
Boolean —
If the XMLList contains simple content, then true; otherwise false.
|
| XML.hasComplexContent(), XML.hasSimpleContent(), hasComplexContent() |
public function length():int
int —
The number of properties in the XMLList object.
|
public function normalize():XMLList
XMLList —
The normalized XMLList object.
|
public function parent():Object
undefined.
Returns
Object —
Returns the parent XML object.
|
public function processingInstructions(name:String = "*"):XMLList
name parameter is provided, lists all the children of the XMLList object that
contain processing instructions with that name. With no parameters, the method lists all the
children of the XMLList object that contain any processing instructions.
Parameters
name:String (default = "*") — The name of the processing instructions to match.
|
XMLList —
An XMLList object that contains the processing instructions for each XML object.
|
| XML.processingInstructions() |
public function propertyIsEnumerable(p:String):Boolean
p is in the set of properties that can be iterated in a for..in statement
applied to the XMLList object. This is true only if toNumber(p) is greater than or equal to 0
and less than the length of the XMLList object.
Parameters
p:String — The index of a property to check.
|
Boolean —
If the property can be iterated in a for..in statement, then true; otherwise false.
|
public function text():XMLList
text() method of each XML
object and returns an XMLList object that contains the results.
Returns
XMLList —
An XMLList object of all XML properties of the XMLList object that represent XML text nodes.
|
| XML.text() |
public function toString():String
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 the toXMLString() method.
String —
The string representation of the XML object.
|
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>
| XMLList.hasSimpleContent(), XMLList.hasComplexContent(), XMLList.toXMLString() |
public function toXMLString():String
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.)
Returns
String —
The string representation of the XML object.
|
| XMLList.toString() |
public function valueOf():XMLList
XMLList —
Returns the current XMLList object.
|
books and adds several
items with book publisher and name tags to a node named books.
Then the showBooksByPublisher() method is called,
which takes the XMLList and returns each item matching the publisher, "Addison-Wesley."
package {
import flash.display.Sprite;
public class XMLListExample extends Sprite {
private var books:XML;
public function XMLListExample() {
books = <books>
<book publisher="Addison-Wesley" name="Design Patterns" />
<book publisher="Addison-Wesley" name="The Pragmatic Programmer" />
<book publisher="Addison-Wesley" name="Test Driven Development" />
<book publisher="Addison-Wesley" name="Refactoring to Patterns" />
<book publisher="O'Reilly Media" name="The Cathedral & the Bazaar" />
<book publisher="O'Reilly Media" name="Unit Test Frameworks" />
</books>;
showBooksByPublisher("Addison-Wesley");
}
private function showBooksByPublisher(name:String):void {
var results:XMLList = books.book.(@publisher == name);
showList(results);
}
private function showList(list:XMLList):void {
var item:XML;
for each(item in list) {
trace("item: " + item.toXMLString());
}
}
}
}