13.08.2012 Views

ACTIONSCRIPT 3 Developer’s Guide en

ACTIONSCRIPT 3 Developer’s Guide en

ACTIONSCRIPT 3 Developer’s Guide en

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>ACTIONSCRIPT</strong> 3.0 DEVELOPER’S GUIDE<br />

Working with XML<br />

If an elem<strong>en</strong>t contains no cont<strong>en</strong>t, it can be writt<strong>en</strong> as an empty elem<strong>en</strong>t (sometimes called a self-closing elem<strong>en</strong>t). In<br />

XML, this elem<strong>en</strong>t:<br />

<br />

is id<strong>en</strong>tical to this elem<strong>en</strong>t:<br />

<br />

In addition to the elem<strong>en</strong>t’s cont<strong>en</strong>t contained betwe<strong>en</strong> the op<strong>en</strong>ing and closing tags, an elem<strong>en</strong>t can also include other<br />

values, known as attributes, defined in the elem<strong>en</strong>t’s op<strong>en</strong>ing tag. For example, this XML elem<strong>en</strong>t defines a single<br />

attribute named l<strong>en</strong>gth, with the value "4:19" :<br />

<br />

Each XML elem<strong>en</strong>t has cont<strong>en</strong>t, which is either a single value, one or more XML elem<strong>en</strong>ts, or nothing (for an empty<br />

elem<strong>en</strong>t).<br />

Learning more about XML<br />

To learn more about working with XML, there are a number of additional books and resources for learning more about<br />

XML, including these web sites:<br />

W3Schools XML Tutorial: http://w3schools.com/xml/<br />

XMLpitstop tutorials, discussion lists, and more: http://xmlpitstop.com/<br />

ActionScript classes for working with XML<br />

ActionScript 3.0 includes several classes that are used for working with XML-structured information. The two main<br />

classes are as follows:<br />

XML: Repres<strong>en</strong>ts a single XML elem<strong>en</strong>t, which can be an XML docum<strong>en</strong>t with multiple childr<strong>en</strong> or a single-value<br />

elem<strong>en</strong>t within a docum<strong>en</strong>t.<br />

XMLList: Repres<strong>en</strong>ts a set of XML elem<strong>en</strong>ts. An XMLList object is used wh<strong>en</strong> there are multiple XML elem<strong>en</strong>ts that<br />

are “siblings” (at the same level, and contained by the same par<strong>en</strong>t, in the XML docum<strong>en</strong>t’s hierarchy). For instance,<br />

an XMLList instance would be the easiest way to work with this set of XML elem<strong>en</strong>ts (presumably contained in an<br />

XML docum<strong>en</strong>t):<br />

Fred Wilson<br />

James Schmidt<br />

Susan Harriet Thurndon<br />

For more advanced uses involving XML namespaces, ActionScript also includes the Namespace and QName classes.<br />

For more information, see “Using XML namespaces” on page 110.<br />

In addition to the built-in classes for working with XML, ActionScript 3.0 also includes several operators that provide<br />

specific functionality for accessing and manipulating XML data. This approach to working with XML using these<br />

classes and operators is known as ECMAScript for XML (E4X), as defined by the ECMA-357 edition 2 specification.<br />

Important concepts and terms<br />

The following refer<strong>en</strong>ce list contains important terms you will <strong>en</strong>counter wh<strong>en</strong> programming XML handling routines:<br />

Elem<strong>en</strong>t A single item in an XML docum<strong>en</strong>t, id<strong>en</strong>tified as the cont<strong>en</strong>t contained betwe<strong>en</strong> a starting tag and an <strong>en</strong>ding<br />

tag (including the tags). XML elem<strong>en</strong>ts can contain text data or other elem<strong>en</strong>ts, or can be empty.<br />

Empty elem<strong>en</strong>t An XML elem<strong>en</strong>t that contains no child elem<strong>en</strong>ts. Empty elem<strong>en</strong>ts are oft<strong>en</strong> writt<strong>en</strong> as self-closing<br />

tags (such as ).<br />

Last updated 6/6/2012<br />

97

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!