actionscript 3 - Adding(removing) data from XML to list -


i want add data dynamically xml class list. xml class this:

<?xml version="1.0" ?>               <persons>                 <person id="1" >                     <firstname>anthony</firstname>                     <lastname>robbins</lastname>                 </person>                 <person id="2" >                     <firstname>deil</firstname>                     <lastname>carnegie</lastname>                 </person>                 <person id="3" >                     <firstname>bill</firstname>                     <lastname>cosby</lastname>                   </person>                 <person id="4" >                     <firstname>albert</firstname>                     <lastname>einestein</lastname>                   </person>                 <person id="5" >                     <firstname>george bernard</firstname>                     <lastname>shaw</lastname>                 </person>             </persons>  

i want add(remove) (first name + last name) of selected id to(from) list every click on button. in other words want add example (first name + last name) of id=4 , other button(like remove button) want remove list.

i used data provider problem adds whole xml class instead of selected element of class. whats solution?

your question not clear me. following solution made question.

<?xml version="1.0" encoding="utf-8"?> <s:application xmlns:fx="http://ns.adobe.com/mxml/2009"                 xmlns:s="library://ns.adobe.com/flex/spark"                 xmlns:mx="library://ns.adobe.com/flex/mx" minwidth="955" minheight="600">     <fx:script>         <![cdata[             import mx.controls.alert;              private var lastid:int = 5;             private function addnode():void             {                 var suffix:int = int(math.random()*100000);                 lastid++;                   var node:string = '<person id="'+lastid+'" >' +                      '<firstname>firstname'+suffix+'</firstname>' +                     '<lastname>lastname'+suffix+'</lastname>' +                     '</person>'                 var xmllist:xmllist = new xmllist(node);                     xmldata.appendchild(xmllist);                 trace(xmldata.toxmlstring())                 txtresult.text = xmldata.tostring();             }              private function removenode():void             {                 try{                     delete xmldata.person[xmllist(xmldata.person.(@id==txtid.text)).childindex()];                     txtresult.text = xmldata.tostring();                 }catch(err:error){                     alert.show("person id not found.");                 }              }          ]]>     </fx:script>     <fx:declarations>         <fx:xml id="xmldata" source="data.xml" />         <!-- place non-visual elements (e.g., services, value objects) here -->     </fx:declarations>     <s:vgroup width="100%" height="100%">         <mx:form>             <mx:formitem label="enter node id:" >                 <mx:textinput id="txtid" restrict="0-9" />              </mx:formitem>             <mx:formitem direction="horizontal">                 <mx:button label="add node" click="addnode()"/>                 <mx:button label="remove node" click="removenode()"/>             </mx:formitem>         </mx:form>         <mx:textarea id="txtresult" width="100%" height="100%" />     </s:vgroup>  </s:application> 

here in code data.xml xml in question.


Comments

Popular posts from this blog

How to mention the localhost in android -

php - Calling a template part from a post -

c# - String.format() DateTime With Arabic culture -