19.1. Understanding XML Structure (Reading and Writing XML)


You want to understand how to read or write XML.


XML is tag-based and hierarchical. If you are familiar with HTML, learning the basics of XML isn’t very difficult.


Although reading and writing good XML is not a skill that is specific to ActionScript, it is, nonetheless, a skill from which your ActionScript can benefit. If you are not yet familiar with XML, don’t worry. This is going to be painless.

XML is a way of representing structured data. This means that you explicitly define the context for the data. For example, without XML you might have a string of data such as:


You can use XML to tell us who these people are:


Now, as you can see, the XML tells us a lot more about the data. Here are a few other points to notice about XML:

  • XML is composed mainly of nodes. A node is a general term that can refer to many parts within the XML. For example, <family> is a node in the preceding XML snippet. These kinds of nodes are called elements. Also, the values such as Jerry, Carolyn, and Laura are nodes. These kinds of nodes are called text nodes.

  • Every XML element must have a matching opening and closing tag. The opening tag might look like <family>, and the closing tag is identical except that it uses a forward slash to indicate it is closing the element, as in </family>. The opening and closing tags ...

Get Actionscript Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.