Reputation: 1695
My Resources
folder contains an XML file. I need to parse it in Titanium. I have written the following code:
try {
var file = Ti.Filesystem.getFile(Ti.Filesystem.resourcesDirectory,'Translation.xml');
var xmltext = file.read().text;
var doc = Ti.XML.parseString(xmltext);
}
catch(e) {
alert(e);
Ti.API.info(e);
}
But I am getting the next error:
- result of expression 'file.read() is not an object
Any solution? Thanks!
Upvotes: 0
Views: 2405
Reputation: 8856
Try to check if your file exists or not.
var file = Ti.Filesystem.getFile(Ti.Filesystem.resourcesDirectory,'Translation.xml');
if ( file.exists() ) {
var xmltext = file.read().text;
var doc = Ti.XML.parseString(xmltext);
}
Upvotes: 3
Reputation: 4066
It looks like the file can't be found on the system, that's why you are getting the error. Try putting the whole path as mentioned bellow. Example:
var file = Titanium.Filesystem.getFile("../Resources/tableWindows/CrossRef.xml");
Somebody with the same problem: http://developer.appcelerator.com/question/123246/xml-file-will-not-read
Upvotes: 1