Hi All,
I'm working on my first AIR1.5 app in Flash CS3/AS3. What I'm trying to do is "APPEND" an XML Node to the end of an XML doc.
Starting XML:
Code:
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<galeria>
<Photo imagem="casinha.jpg" legenda="Minha casa"/>
<Photo imagem="familia.jpg" legenda="FamÃ*lia reunida"/>
</galeria>
Im able to write to the XML file but it adds the node to the end of the XML out side of the "<galeria></galeria> Node".
Code:
var fl:File = File.desktopDirectory.resolvePath("air/testFile.xml");
var fs:FileStream = new FileStream();
fs.addEventListener(Event.COMPLETE, processXMLData);
fs.openAsync(fl, FileMode.READ);
var xml:XML;
//
function processXMLData(e:Event):void {
xml = XML(fs.readUTFBytes(fs.bytesAvailable));
testtext.text = xml;
writeXML();
}
function writeXML():void {
//fs.openAsync(fl, FileMode.WRITE);
fs.openAsync(fl, FileMode.APPEND);
var xmlNew = '<Photo imagem="NodeToBeAdded.jpg" legenda="Node to be added" />';
fs.writeUTFBytes(xmlNew);
testtext.text = xml;
fs.close();
}
So I end up with this XML:
Code:
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<galeria>
<Photo imagem="casinha.jpg" legenda="Minha casa"/>
<Photo imagem="familia.jpg" legenda="FamÃ*lia reunida"/>
</galeria><Photo imagem="NodeToBeAdded.jpg" legenda="Node to be added" />
this is the XML I want:
Code:
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<galeria>
<Photo imagem="casinha.jpg" legenda="Minha casa"/>
<Photo imagem="familia.jpg" legenda="FamÃ*lia reunida"/>
<Photo imagem="NodeToBeAdded.jpg" legenda="Node to be added" />
</galeria>
If anyone has a tutorial of a sample code I would really appreciate it.
Thanks
Scott
Any help would be appreciated.