PDA

View Full Version : writing XML with AIR


eliddell
01-11-2008, 08:34 PM
im trying to open an existing XML document and then write to it with AIR using flash..


import flash.filesystem.File;
import flash.filesystem.FileStream;
import flash.filesystem.FileMode;

var appDir:File = File.applicationStorageDirectory
var dskTopFileStream:FileStream = new FileStream();
var fileString:String = appDir.nativePath;
var dskTopFile:File = File.documentsDirectory;
trace(dskTopFile);
dskTopFile = dskTopFile.resolvePath(fileString+"\\bankroll.xml");



// LOAD XML
var xmlString:URLRequest = new URLRequest(fileString+"\\bankRoll.xml");
var xmlLoader:URLLoader = new URLLoader(xmlString);
xmlLoader.addEventListener("complete", init);
var defaultXML:XMLDocument = new XMLDocument();
defaultXML.ignoreWhite = true;

function init(event:Event):void {
var xml:XML = XML(xmlLoader.data);
defaultXML.parseXML(xml.toXMLString());
//var myString:String = defaultXML.firstChild
var existingData = defaultXML.firstChild.childNodes
trace(existingData)
var i = 0
for (i=0;i<defaultXML.firstChild.childNodes.length-1;i++) {
trace(i)

}

dskTopFileStream.openAsync (dskTopFile, FileMode.WRITE);
dskTopFileStream.writeUTFBytes ("<BankRoll>"+ existingData+existingData+"</BankRoll>");
dskTopFileStream.close ();


}





problem is, it keeps inserting weird charecters and placing commas etc between my childNodes.. this effect seems much like an old php problem i use to encounter having something to do with a setting in the php server..

any ideas?

erik
eliddell is online now Report Post Edit/Delete Message

eliddell
01-13-2008, 07:20 PM
i figured it out... whats wrong with the script above is that my var existing data is an array because of the multiple nodes... thus the commas.. solution:
build the var piece by piece in the for loop

but thanks anyway

xmen
05-11-2010, 05:34 AM
Can you post your solution please?! Im having troubles with the root element when i try to update the xml file,any idea?!

check out my topic -->
http://www.actionscript.org/forums/showthread.php3?t=238173