moock.org is supported in part by


April 10, 2007

Chapter 18, Paragraphs 1-5, Essential ActionScript 3.0

Here are the first 5 paragraphs of Chapter 18 of Essential ActionScript 3.0

18. XML and E4X

Since Flash Player 5, ActionScript has included tools for working with XML-structured data. In ActionScript 1.0 and ActionScript 2.0, XML data was created and manipulated with the variables and methods of the built-in XML class (e.g., firstChild, nextSibling, appendChild(), etc.). The XML class was based on the W3C Document Object Model, or DOM, a standard for interacting with XML documents programmatically (see http://www.w3.org/DOM).

As of ActionScript 3.0, the toolset for creating and manipulating XML has been completely overhauled. ActionScript 3.0 implements ECMAScript for XML (“E4X”), an official ECMA-262 language extension for working with XML as a native datatype. E4X seeks to improve the usability and flexibility of working with XML in ECMA-262-based languages (including ActionScript and JavaScript).

Understanding XML Data as a Hierarchy

Before we can learn to manipulate XML data with E4X, we must first understand the general principle of XML as hierarchical data. Both the legacy XML class and E4X treat XML data as a hierarchical tree in which each element and text block is considered a tree node (i.e., a branch or a leaf). For example, consider the XML fragment in Example 18-1. (An XML fragment is a section of XML excerpted from an XML document.)

Example 18-1. An example XML fragment

<BOOK ISBN="0141182806">
   <TITLE>Ulysses</TITLE>
   <AUTHOR>Joyce, James</AUTHOR>
   <PUBLISHER>Penguin Books Ltd</PUBLISHER>
</BOOK>

The elements <BOOK>, <TITLE>, <AUTHOR>, and <PUBLISHER>, and the text "Ulysses", "Joyce, James", and "Penguin Books Ltd" are all considered nodes on the tree, as depicted in Figure 18-1.

Posted by moock at April 10, 2007 11:05 PM