I am quite new to dealing with xml files through Flash and Action Script 3.0.
I write this piece of code with the intention of changing all the QUESTION children into WRONG.
var urlRequest:URLRequest = new URLRequest("question.xml");
var urlLoader:URLLoader = new URLLoader();
urlLoader.dataFormat = URLLoaderDataFormat.TEXT;
urlLoader.addEventListener(Event.COMPLETE, urlLoader_complete, false, 0, true);
urlLoader.load(urlRequest);
private function urlLoader_complete(e:Event):void {
var question:XML = new XML(e.target.data);
question.QUESTION.setName("WRONG");
trace("FINISH!");
}
The program runs and I successfully got the word Finish traced. However when I check the xml file question.xml, not one of the QUESTION children is renamed.
Can someone explain this for me?
Thanks a lot
setNameis the correct method, but in your example, you are not using it on the individual nodes, but on the XMLList that is returned byquestion.QUESTION– which, technically, does not appear in the XML tree, and therefore does not reflect the change within the XML output.You need to iterate over the actual nodes to get a result:
Or for a single node: