Skip to Main Content
Essential ActionScript 3.0
book

Essential ActionScript 3.0

by Colin Moock
June 2007
Intermediate to advanced content levelIntermediate to advanced
948 pages
27h 2m
English
O'Reilly Media, Inc.
Content preview from Essential ActionScript 3.0

Chapter 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 ...

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.
Start your free trial

You might also like

Essential ActionScript 2.0

Essential ActionScript 2.0

Colin Moock
The ActionScript 3.0 Quick Reference Guide

The ActionScript 3.0 Quick Reference Guide

Jen deHaan, David Stiller, Darren Richardson, Rich Shupe
ActionScript 3.0 Cookbook

ActionScript 3.0 Cookbook

Joey Lott, Darron Schall, Keith Peters

Publisher Resources

ISBN: 0596526946Errata