The E4X filtering predicate operator is a simple but powerful search tool. It can take any XMLList and return a subset of items from that list based on a specified condition. (The term predicate is borrowed from the W3C's XPath Language. See http://www.w3.org/TR/xpath20/#id-predicates.)
The filtering predicate operator takes the general form:
For each item in
conditionExpression is executed once. If
true for an item, that item is added to an
XMLList that is returned after
all items have been processed. Note that during each execution of the
conditionExpression, the current item is
temporarily added to the front of the scope chain, allowing the item's
child elements and attributes to be referenced directly by name within
The filtering predicate operator is extremely intuitive to use. Let's take a look at a new XML fragment and do some filtering! Example 18-12, the new fragment, represents a company's staff list.
Example 18-12. An employee list
var staff:XML = <STAFF> <EMPLOYEE ID="501" HIRED="1090728000000"> <NAME>Marco Crawley</NAME> <MANAGER>James Porter</MANAGER> <SALARY>25000</SALARY> <POSITION>Designer</POSITION> </EMPLOYEE> <EMPLOYEE ID="500" HIRED="1078462800000"> <NAME>Graham Barton</NAME> <MANAGER>James Porter</MANAGER> <SALARY>35000</SALARY> <POSITION>Designer</POSITION> </EMPLOYEE> <EMPLOYEE ID="238" HIRED="1014699600000"> <NAME>James Porter</NAME> <MANAGER>Dorian ...