Open a stored xml file via XHR
I stored an XML file via HTTPrequest
var f =Titanium.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory,'data.xml');
f.write(this.responseData);
and confirmed that the file is there
var file=….
if(file.exists()){
Ti.API.info('in file ' + file.nativePath);
var fcontent = file.read();
Ti.API.info('contents = ' + contents.text);
}
But How do you open a stored XML file, turn it XML object, for instance, like HTTPRequest responseXML.documentElement?
I tried xhr.open("GET",file.nativePath) but it doesn't work.
Thanks
1 Answer
-
Accepted Answer
your code at all will neather do a XHR request to got XML from internet, also you can't do that to open your xml file like you do!
Do XHR request like this:
var xhr = Titanium.Network.createHTTPClient(); xhr.onload = function() { ....your code to save the xml to a file..... (this.responseText) }; // open the client xhr.open('GET','http://twitter.com/statuses/show/123.xml'); // send the data xhr.send();
and if you load your file from filesystem (see KitchenSink Examples)
you could parse the string to a XML object again….var xmlObject = Ti.XML.parseString(xmlString); nodeObject = xmlObject.documentElement.getElementsByTagName("someNodes");