Languages

Menu
Sites
Language
Tizen Wearable - Access local XML file

Greetings.

I want to include XML file with some data with my application for Tizen Wearable, e.g. put it into *.wgt file next to all other resources.

However it's not very clear how can I read it at runtime? I know how to parse it, but I need to read the file itself into a string first.
All solutions that I've found suggest using XMLHttpRequest, but they are all related to usual Web-development, and I'm pretty confident that it can't be that accessing LOCAL (for the application) file requires sending AJAX requests.

So the question is - how to open and read local text file into a string?

Thanks in advance.

View Selected Answer

Responses

2 Replies
Marco Buettner

I prefer XMLHttpRequest... But you can also use "FileSystem API" and the method "readAsString"

Mark as answer
Nate River

I think using HTTP is a bit of an overkill for local files.

So for anyone interested in the same task, here is the solution I came up with thanks to Marco Buettner:

tizen.filesystem.resolve(
	'wgt-package',
	function(dir) {
		var data = dir.resolve('res/data.xml');
		if (data) {
			data.readAsText(function (arg) {
				document.getElementsByClassName('ui-content')[0].innerText = arg;
			});
		}
	},
	function(e) {
		console.log("Error: " + e.message);
	},
	"r"
 );

The key to this solution is 'wgt-package' as a first argument to filesystem.resolve, it allows to access all widget internal files.

Also be sure to include "http://tizen.org/privilege/filesystem.read" privilege to access FileSystem API.