86 | Chapter 4: AIR Mini-Cookbook
</head>
<body onload="doLoad( )">
<textarea id="editor"></textarea>
</body>
</html>
Loading Data from an XML File
Problem
You want to read XML data from a local file using common
JavaScript techniques, and be able to manipulate the DOM
not just the character data.
Solution
Reading a local XML document for the data can occur using
theXMLHttpRequestobject, and by using aFileobject refer-
ence as the URI endpoint as opposed to a web address.
Discussion
Most JavaScript libraries, and virtually every data-oriented
Ajax application uses theXMLHttpRequestobject to load data.
This is a common means to accessing data from the client
without refreshing the page, and is core to Ajax develop-
ment techniques. Adobe AIR includes support for the
XMLHttpRequest object, which can be used for data access.
TheXMLHttpRequest.open( )method expects three arguments.
The first argument is the HTTP method to be used for the call,
which is commonly GET or POST. The third argument tells
the object whether or not it should make the request asynchro-
nously. The challenge in an AIR application is the second
argument that tells the object where to get its data:
XMLHttpRequest.open( "GET", "myData.xml", true );
This URI endpoint generally points to a remote server. This
can still happen in an application that is online, but as AIR