Few months back i made a post on this “Generate XML Data dynamically in Flex” and it needed some improvements. so here i am with the improvements. [ As few readers suggested ]
Lets talk whats are the things required here ::
1. Again explaining the previous post with example and populating DataGrid with that XML Data Generated.
2. Manipulating the Generated XML Data.
These two points will be covered and one in this Post and one in the next one.so stay tuned 🙂 .
Covering the first One ::
To generate XML Data we got to use the Class XML and a bit of Action Script Coding.
First Create the Outer root for the XML in AS.
public var xmlData:XML=<ROOTS></ROOTS>;
Now write a function where in you want to Add the Data of few controls to the XML.
Like for example i am having three controls.
<mx:TextInput x=”167″ y=”78″ id=”txt”/>
<mx:TextArea x=”167″ y=”153″ id=”txta”/>
<mx:DateField x=”167″ y=”114″ width=”160″ id=”dtf”/>
and i want to add the Data of these controls to the XML.So the Function would be like this on click of a Button here.
private function fnAddItem(e:Event):void
appendChild() is the method to add a child element to the XML as the name suggests and its from the XML Class .And Here dg is the instance of a DataGrid. Like below. And observe the assingment of the XML to the DataGrid we got to mention the repeating nodes in the XML.Here its ROOT.
<mx:DataGrid x=”167″ y=”222″ id=”dg”>
<mx:DataGridColumn headerText=”Column 1″ dataField=”TXT”/>
<mx:DataGridColumn headerText=”Column 2″ dataField=”TXTA”/>
<mx:DataGridColumn headerText=”Column 3″ dataField=”DTF”/>
So i am populting the Generated XMl data to my DataGrid.
Check out the example of this here. so this is about the first Point and the next one will be made soon.
Leave any comments for queries.Enjoy the Post 🙂 .