Adobe FLEX 2-PROGRAMMING ACTIONSCRIPT 3.0 Manual page 325

Programming actionscript 3.0
Table of Contents

Advertisement

Filtering by attribute or element value
You can use the parentheses operators—
name or attribute value. Consider the following XML object:
var x:XML =
<employeeList>
<employee id="347">
<lastName>Zmed</lastName>
<firstName>Sue</firstName>
<position>Data analyst</position>
</employee>
<employee id="348">
<lastName>McGee</lastName>
<firstName>Chuck</firstName>
<position>Jr. data analyst</position>
</employee>
</employeeList>
The following expressions are all valid:
x.employee.(lastName == "McGee")
x.employee.(lastName == "McGee").firstName
the second
employee
x.employee.(lastName == "McGee").@id
second
employee
x.employee.(@id == 347)
x.employee.(@id == 347).lastName
node.
employee
x.employee.(@id > 300)
x.employee.(position.toString().search("analyst") > -1)
XMLList with both
If you try to filter on attributes or elements that may not exist, Flash Player will throw an
exception. For example, the final line of following code generates an errors because there is no
attribute in the second
id
var doc:XML =
<body>
<p id='123'>Hello, <b>Bob</b>.</p>
<p>Hello.</p>
</body>;
trace(doc.p.(@id == '123'));
(
node.
node.
—The first
—This is an XMLList with both
properties.
position
element:
p
and
—to filter elements with a specific element
)
—This is the second
—This is the
—This is the value of the
node.
employee
—This is the
lastName
node.
employee
property of
firstName
attribute of the
id
property of the first
properties.
employee
—This is an
Traversing XML structures
325

Advertisement

Table of Contents
loading

This manual is also suitable for:

Flex

Table of Contents