Subject: read write xml file
hi
I am on Mac and on Titanium 0.8.2. i am building for Android
platform.
i have a database.xml file in my resources. i read that file using the following code:
var readscoreContents;
var xmlfilename = Titanium.Filesystem.getResourcesDirectory() + "database.xml";
Titanium.API.info(xmlfilename);
var readscoreFile = Titanium.Filesystem.getFile(Titanium.Filesystem.getResourcesDirectory(), "database.xml");
if (readscoreFile.exists())
{
readscoreContents = readscoreFile.read();
}
var xmlscoreDoc;
var xmlscoreString =readscoreContents.toString();
if (document.implementation.createDocument) {
var sparser = new DOMParser();
xmlscoreDoc = sparser.parseFromString(xmlscoreString, "text/xml");
} else if (window.ActiveXObject) {
xmlscoreDoc = new ActiveXObject("Microsoft.XMLDOM");
xmlscoreDoc.async="false";
xmlscoreDoc.loadXML(xmlscoreString);
}
then i create a new node to append in the xml file.
var root2 =
xmlscoreDoc.getElementsByTagName("scores")[0];
var newel=xmlscoreDoc.createElement("score");
root2.appendChild(newel);
Now i need to save this file to reflect the changes in
database.xml file.
Please guide me with the code to save the xml file.
This is my database.xml file structure :
<?xml version="1.0" encoding="UTF-8"?>
<scores>
</scores>
I want to add a "score" tag to this file inside "scores" tag.
Thanks
Comments are currently closed for this discussion. You can start a new one.
Support Staff 2 Posted by Kevin Whinnery on 08 Feb, 2010 04:52 PM
Around line 117 is an example:
http://github.com/kwhinnery/KitchenSink/blob/master/0.8.1/KitchenSi...
3 Posted by hirva patel on 09 Feb, 2010 02:37 AM
hi
i modified the code to
http://pastie.org/815670
i get this error...
[ERROR] checking: Resource file may not be written.
any help
Support Staff 4 Posted by Don Thorp on 09 Feb, 2010 02:54 AM
You can't write to the resources directory. You can write to the
ApplicationDataDirectory
hth
5 Posted by hirva patel on 09 Feb, 2010 02:57 AM
ok thanks for the reply.