mardi 29 septembre 2015

How to add, edit, delete and save xml node in as3

My xml file is like this,

<GALLERY COLUMNS="3" XPOSITION="30" YPOSITION="30" WIDTH="150" HEIGHT="150">
<IMAGE FULL="Tinku.png" Title="Tinku" THUMB="thumbs/thumb1.jpg" Path="file:///storage/emulated/0/Raconteur/Tinku" />
<IMAGE FULL="Kaal.png" Title="Kaal" THUMB="thumbs/thumb2.jpg" Path="file:///storage/emulated/0/Raconteur/Kaal" />
<IMAGE FULL="Painters.png" Title="Little Painters" THUMB="thumbs/thumb3.jpg" Path="file:///storage/emulated/0/Raconteur/Painters" />
</GALLERY>

How to add a new node like the one below,

<IMAGE FULL="Lost.png" Title="Lost and Found" THUMB="thumbs/thumb4.jpg" Path="file:///storage/emulated/0/Raconteur/Lost" />

Also i want to know how to delete a particular node

var myXMLLoader:URLLoader = new URLLoader();
            myXMLLoader.load(new URLRequest("gallery.xml"));
            myXMLLoader.addEventListener(Event.COMPLETE, processXML);

        function processXML(e:Event):void {
            myXML = new XML(e.target.data);
            images = myXML.IMAGE;
            total = images.length();
            myXMLLoader.removeEventListener(Event.COMPLETE, processXML);
            myXMLLoader = null;             
            var imageName:String = images[i].@FULL;
            loader = new Loader();
            loader.load(new URLRequest("images/" + imageName));
        }

add_bt.addEventListener(MouseEvent.CLICK, addnode);
private function addnode(e:MouseEvent):void
        {
            var new_node:XML = <IMAGE FULL="Lost.png" Title="Lost and Found" THUMB="thumbs/thumb4.jpg" Path="file:///storage/emulated/0/Raconteur/Lost" />
            myXML.appendChild(new_node);
            trace(myXML);
        }

Thanks in advance

Aucun commentaire:

Enregistrer un commentaire