ADOBE FLEX 3
Developer Guide
210
Important concepts and terms
The following reference list contains important terms used in this chapter:
Element: A single item in an XML document, identified as the content contained between a starting tag and an
ending tag (including the tags). XML elements can contain text data or other elements, or can be empty.
Empty element: An XML element that contains no child elements. Empty elements are often written as self-
closing tags (such as
<element/>).
Document: A single XML structure. An XML document can contain any number of elements (or can consist
only of a single empty element); however, an XML document must have a single top-level element that contains all
the other elements in the document.
Node: Another name for an XML element.
Attribute: A named value associated with an element that is written into the opening tag of the element in
attributename="value" format, rather than being written as a separate child element nested inside the element.
The E4X approach to XML processing
The ECMAScript for XML specification defines a set of classes and functionality for working with XML data. These
classes and functionality are known collectively as E4X. ActionScript 3.0 includes the following E4X classes: XML,
XMLList, QName, and Namespace.
The methods, properties, and operators of the E4X classes are designed with the following goals:
Simplicity—Where possible, E4X makes it easier to write and understand code for working with XML data.
Consistency—The methods and reasoning behind E4X are internally consistent and consistent with other parts
of ActionScript.
Familiarity—You manipulate XML data with well-known operators, such as the dot (.) operator.
Note: There was an XML class in ActionScript 2.0. In ActionScript 3.0 it has been renamed XMLDocument, so that it
does not conflict with the ActionScript 3.0 XML class that is part of E4X. In ActionScript 3.0, the legacy classes—
XMLDocument, XMLNode, XMLParser, and XMLTag—are included in the flash.xml package primarily for legacy
support. The new E4X classes are core classes; you need not import a package to use them. This chapter does not go into
detail on the legacy ActionScript 2.0 XML classes. For details on these, see the flash.xml package in the ActionScript 3.0
Language and Components Reference.
Here is an example of manipulating data with E4X:
var myXML:XML =
<order>
<item id='1'>
<menuName>burger</menuName>
<price>3.95</price>
</item>
<item id='2'>
<menuName>fries</menuName>
<price>1.45</price>
</item>
</order>
Often, your application will load XML data from an external source, such as a web service or a RSS feed. However,
for clarity, the examples in this chapter assign XML data as literals.

Get ADOBE® FLEX® 3: PROGRAMMING ACTIONSCRIPT™ 3.0 now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.