Home > Articles > Web Services > XML

XML Structure

  • Print
  • + Share This
In this chapter, Dov and Jesse Jacobson closely examine the XML specification and teach you how to create a well-formed XML document.
This chapter is excerpted from Flash and XML: A Developer's Guide, by Dov and Jesse Jacobson.
This chapter is from the book

This chapter is from the book

In this chapter we closely examine the XML specification and learn how to create a well-formed XML document. The relevance of each topic to ActionScript is considered, often in the light of an evolving implementation.

Readers with moderate experience in XML might find this chapter useful. Each time the XML specification is restated in English, a new perspective is formed. XML workers might find a tiny highlight in this formulation that rounds out their mental image, if only by raising objections.

Even busy XML experts should read the sections entitled Flash Context. These sections point out the differences between the XML specification and the ActionScript implementation at the time of writing and as anticipated in the future.


An XML document is simply a tree composed of a hierarchy of elements. In fact the document (exclusive of its optional prologue and extremely rare epilogue) is a single XML element. Since an element includes its child elements, a thousand-element tree, if properly formed, is also a single element—the one at the root.

Flash Context

An element appears in the Flash dataspace as a node. The root element appears as the only child element of the document. Each element has multiple pointers into the hierarchy: parent, siblings, and children. Each carries a list of the names and values of all its attributes. In subsequent chapters we become familiar with the precise arrangement of these data, and we become comfortable tracing and manipulating them.


An element is bracketed by a pair of tags. The information between these tags is the content of the element. The content can be nothing (it often is) or it can be a hideously complex and bulky data structure with hundreds of other complicated elements (it often is). Attribute information, if present, must be embedded in the start tag.The form of the element ID:

<start tag>optional content</end tag>

In the case of an empty element (which contains no content, though it has a name and may have attributes), the start tag and end tag are immediately consecutive and can be fused into a special symbol:

<empty element tag/>


Each element must have

  • a start tag, introducing its Name

  • an end tag (in some cases these two tags are fused)

Additionally, every element can contain any, all, or none of the following:

  • More elements

  • Text

  • Attributes

  • Entity references

  • Processing instructions

  • Comments

It may not have

  • XML declaration

  • document declaration

  • unterminated elements, references, comments, processor instructions

  • duplicate assignment of attribute

Examples of Elements

<Address>125 Main St</Address>

Address element with street number as content

<Address>Fourscore... earth.</Address>

Another address; it is up to the XML author

<Address line="city">N.Y.C.</Address>

Element with content and attribute assignment

<Address>New York <b>City</b></Address>

Element whose content includes another element

<Address line="apartment"/>

Empty element with an attribute


Empty element containing only a name token

Bad examples

<Address line="optional" line="zip"/>

Multiple assignments of the same attribute

<Address>New York <br>City</Address>

Incomplete inner element

<Address>New York <b>City</Address></b>

Incomplete element: improper nesting

  • + Share This
  • 🔖 Save To Your Account