Sending and loading variables to and from a remote source 181
About XML
XML (Extensible Markup Language) is becoming the standard for the interchange of structured
data in Internet applications. You can integrate data in Flash with servers that use XML
technology to build sophisticated applications, such as chat systems or brokerage systems.
In XML, as with HTML, you use tags to mark up, or specify, a body of text. In HTML, you use
predefined tags to indicate how text should appear in a web browser (for example, the
<b> tag
indicates that text should be bold). In XML, you define tags that identify the type of a piece of
data (for example,
<password>VerySecret</password>). XML separates the structure of the
information from the way it’s displayed, so the same XML document can be used and reused in
different environments.
Every XML tag is called a node, or an element. Each node has a type (1, which indicates an XML
element, or 3, which indicates a text node), and elements may also have attributes. A node nested
in a node is called a child node. This hierarchical tree structure of nodes is called the XML
Document Object Model (DOM)—much like the JavaScript DOM, which is the structure of
elements in a web browser.
In the following example,
<PORTFOLIO> is the parent node; it has no attributes and contains the
child node
<HOLDING>, which has the attributes SYMBOL, QTY, PRICE, and VALUE:
<PORTFOLIO>
<HOLDING SYMBOL="RICH"
QTY="75"
PRICE="245.50"
VALUE="18412.50" />
</PORTFOLIO>
Using the XML class
The methods of the ActionScript XML class (for example,
appendChild(), removeNode(), and
insertBefore()) let you structure XML data in Flash to send to a server and manipulate and
interpret downloaded XML data.
The following XML class methods send and load XML data to a server by using the HTTP
POST method:
• The load() method downloads XML from a URL and places it in an ActionScript
XML object.
• The send() method passes an XML object to a URL. Any returned information is sent to
another browser window.
• The sendAndLoad() method sends an XML object to a URL. Any returned information is
placed in an ActionScript XML object.
For example, you could create a brokerage system that stores all its information (user names,
passwords, session IDs, portfolio holdings, and transaction information) in a database.