update xml inside a root node

janetsnail

New Member
I cant seem to get my xml to generate inside the node. it repeats the entire xml structure every time. the use case is that this file will be repeatedly updated over hours/days. this xml file also connects to a backend so it's critical that i keep it in this format.currently the xml ends up looking like this:\[code\]<xmlcontainer> <details> <name>name</name> <phone>phone</phone> <email>email</email> <image>0</image> <image>1</image> </details></xmlcontainer><xmlcontainer> <details> <name>name2</name> <phone>phone2</phone> <email>email2</email> <image>3</image> <image>4</image> </details></xmlcontainer>\[/code\]when it should look like this.\[code\]<xmlcontainer> <details> <name>name</name> <phone>phone</phone> <email>email</email> <image>0</image> <image>1</image> </details> <details> <name>name2</name> <phone>phone2</phone> <email>email2</email> <image>3</image> <image>4</image> </details></xmlcontainer>\[/code\]below is my code, spanning across 2 frames. what am i missing that's making this happen?i messed with fs.open(fl2,FileMode.APPEND); and fs.open(fl2,FileMode.WRITE); but it doesnt appear to make any big difference.thanks\[code\]//frame 2var xml_file = File.documentsDirectory.resolvePath('app/information.xml').nativePath; var xml_created = false; var xml_datahttp://stackoverflow.com/questions/10942534/= ""; function load_xml(f_name){ var target_url:URLRequest = new URLRequest(f_name); var target_load:URLLoader= new URLLoader(); var xmlData : XML = new XML(); target_load.load(target_url); target_load.addEventListener(Event.COMPLETE, target_complete); target_load.addEventListener(IOErrorEvent.IO_ERROR, target_error); function target_complete (evt:Event):void { xmlData = http://stackoverflow.com/questions/10942534/new XML(evt.target.data); xml_created = true; xml_data = String(xmlData.details); nextFrame(); trace("OK - load XML") } function target_error(evt:IOErrorEvent):void { nextFrame(); trace("ERROR - load xml - check xml file name"); } } load_xml(xml_file);//frame 5function saveFiles_fun (){ var xmlData:XML = new XML(<xmlcontainer> </xmlcontainer> ); var details:XML = new XML(<details/>) //client.appendChild(<id/>); details.appendChild( new XML( "<name>qwe</name>" )); details.appendChild( new XML( "<phone>qwe</phone>" )); details.appendChild( new XML( "<email>qwe</email>" )); for (var fna:int = 0; fna<fileNameArray.length; fna++) { details.appendChild( new XML( "<image>" + fna + "</image>" )); } xmlData.appendChild(details); var fl1:File = File.applicationDirectory.resolvePath(xml_file); var fl2:File = new File( fl1.nativePath ); var fs:FileStream = new FileStream(); try{ fs.open(fl2,FileMode.APPEND); fs.writeUTFBytes(xmlData); fs.close(); doSomething(); }catch(e:Error){}}function doSomething(){ form.alert.text = alert4; var _tim5 = setTimeout(gotoAndPlay, 1000,1);}\[/code\]
 
Back
Top