User Guide

311
11
CHAPTER 11
Working with XML
ActionScript 3.0 includes a group of classes based on the ECMAScript for XML (E4X)
specification (ECMA-357 edition 2). These classes include powerful and easy-to-use
functionality for working with XML data. Using E4X, you will be able to develop code with
XML data faster than was possible with previous programming techniques. As an added
benefit, the code you produce will be easier to read.
This chapter describes how to use E4X to process XML data.
Contents
A quick introduction to XML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 312
The E4X approach to XML processing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 313
XML objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 315
XMLList objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 317
Initializing XML variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 319
Assembling and transforming XML objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 320
Traversing XML structures. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .322
Using XML namespaces. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .327
XML type conversion. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .328
Reading external XML documents. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 330
Example: Loading RSS data from the Internet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 330