Parsing XML and Display in a tableView for Android
So I have been trying to do this for a while. Looking at all the Q&A here in the forum for parsing XML (locally, externally etc) and nothing seems to work for me. Here's my code…
var win = Titanium.UI.currentWindow;
//load local xml file
var file = Ti.Filesystem.getFile(Ti.Filesystem.resourcesDirectory,'test.xml');
var xmltext = file.read().text;
var doc = Ti.XML.parseString(xmltext);
//get data from xml file and store in a list
var custList = doc.documentElement.getElementsByTagName("customer");
//create an array and save the data into array
var custArray = [];
for(var i = 0; i<custList.length;i++)
{
custArray[i] = custList.item(i).text;
};
var rows = Ti.UI.createTableViewRow({data:custArray});
var tableView = Titanium.UI.createTableView({data:custArray});
win.add(tableView);
And no info appears in the list. My XML is formatted correctly, I've already checked that.
I've seen some people use createTableViewRow with createLabel but it throws an error whenever I use tableViewRow. Any help would be greatly appreciated.
1 Answer
-
Try replacing:
var xmltext = file.read().text;
with:
var xmltext = file.read().toString();