Reputation: 3406
I would like to know how to parse XML file from local in Titanium App?
var file = Titanium.Filesystem.getFile("Translation1.xml");
if ( file.exists() ) {
Ti.API.info("found");
var xmltext = file.read().text;
var doc = Ti.XML.parseString(xmltext);
// var books = xmlMessage.documentElement.getElementsByTagName("DUAS");
// Ti.API.info(xmltext.length); //Returns 50
Ti.API.info(xmltext); //Returns [Ti.Document
}
else
{
Ti.API.info("not found");
}
}
catch(e)
{
alert(e);
Ti.API.info(e);
}
i get only first line of the file, like following
<?xml version="1.0" encoding="utf-8" ?>
how can i get all the data from that xml file?
Upvotes: 1
Views: 4729
Reputation: 471
After you have parse the string, you have to search the elements too:
var doc = Ti.XML.parseString(xmltext);
var results = doc.getElementsByTagName('yourxmltag');
Now you can loop for each of the element found:
var arr = [];
for(var i=0; i<results.length; i++){
arr[i] = results.item(i).text;
}
Now arr
array has your results.
Upvotes: 0
Reputation: 7038
You should start by reading the 'Working with XML Data' guide.
Upvotes: 1