Load the file using an AJAX request from a local URL, then parse it using the DOMParser class.
//create a setupRealData function that I can call from somewhere in my app
StartAssistant.prototype.setupRealData = function() {
var url = "content/content.xml";
var request = new Ajax.Request(url, {
method: 'get',
evalJSON: 'false', //to enforce parsing JSON if there is JSON response
onCreate: function(){console.info('******* onCreate happened')},
onLoading: function(){console.info('******* onLoading happened')},
onLoaded: function(){console.info('******* onLoaded happened')},
onSuccess: function(){console.info('******* onComplete happened')},
onComplete: this.gotResults.bind(this),
onFailure: this.failure.bind(this)
});
}
//this function will by called when AJAX request above returns successfully
StartAssistant.prototype.gotResults = function(event){
console.log("got the results");
var xmlstring = event.responseText;
// parse into a DOM document object
var xmlobject = (new DOMParser()).parseFromString(xmlstring, "text/xml");
// Use xpath to get the parts of the XML I care about
var nodes = document.evaluate("/content/section", xmlobject, null, XPathResult.ANY_TYPE, null);
var section = nodes.iterateNext();
while (section)
{
console.log("section = " + section);
section=nodes.iterateNext();
}
}