File API | 87
applications can also work offline, the endpoint needs to be
pointed to a local resource. Rather than pass an endpoint to
a remote server, a File reference can be provided:
var file = air.File.applicationStorageDirectory.resolve(
"myData.xml" );
var xml = new XMLHttpRequest( );
xml.onreadystatechange = function( )
{
if( xml.readystate == 4 )
{
// Work with data
}
}
xml.open( "GET", file.url, true );
xml.send( null );
The key distinction to make for this example is the use of the
File.urlproperty, which theXMLHttpRequestobject under-
stands and uses to access the appropriate data. Using this
approach results in a traditional DOM that can be used to
traverse and manipulate the XML data in the file. Addition-
ally, this approach can be used with common JavaScript
libraries.
Given
<rolodex>
<contact>
<first>Kevin</first>
<last>Hoyt</last>
</contact>
...
</rolodex>
Example
<html>
<head>
<title>XML File Access</title>
<script type="text/javascript" src="AIRAliases.js">
</script>