Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

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

— asked May 5th 2010 by Daniel Lim
  • cache
  • file
  • filesystem
  • ipad
  • iphone
  • xhr
  • xml
0 Comments

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");
    
    — answered May 5th 2010 by Marc Bender
    permalink
    0 Comments
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.