Using XML
XML is a standard protocol for transferring, storing, and reading data for several purposes, including application initialization parameters, data sets, and remote procedure calls. Flex applications work with XML by using Flash Player’s native support.
Flash Player 9 supports two mechanisms for working with XML: a legacy
XMLDocument class
and the new XML class
that implements the ECMAScript for XML (E4X) standard. All XML examples in this book use E4X unless otherwise
noted.
Creating XML Objects
There are two ways to create XML objects in ActionScript: using XML
literals or with the XML constructor.
XML literals are useful when you want to define the XML data directly in
the code and you know the exact XML data you want to use. The following
example defines an XML literal and assigns it to a variable:
var xml:XML = <books>
<book>
<title>Programming Flex 3</title>
<authors>
<author first="Chafic" last="Kazoun" />
<author first="Joey" last="Lott" />
</authors>
</book>
<book>
<title>ActionScript 3.0 Cookbook</title>
<authors>
<author first="Joey" last="Lott" />
<author first="Keith" last="Peters" />
<author first="Darron" last="Schall" />
</authors>
</book>
</books>;Note
We’ll assume that this is the XML object referenced by the remainder of
the XML examples in this chapter.
If you aren’t able to define the XML data directly in
ActionScript, you can load the data as a string and pass it to the
XML constructor. In the following example, loadedXMLData is a variable containing XML ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access