FLEX XML to Collection Part 5
Following example show XML to ArrayCollection use XML Class
XMLToCollection5.mxml
<?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" viewSourceURL="srcview/index.html">
<s:layout>
<s:VerticalLayout verticalAlign="middle"
horizontalAlign="center"/>
</s:layout>
<fx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
import mx.events.FlexEvent;
[Bindable]
private var myDB:ArrayCollection;
private var arr:Array=new Array();
protected function dg_creationCompleteHandler(event:FlexEvent):void
{
for (var i:int; i < this.myXML.product.length(); i++)
{
arr.push(this.myXML.product[i]);
}
this.myDB=new ArrayCollection(arr);
}
]]>
</fx:Script>
<fx:Declarations>
<fx:XML id="myXML"
source="assets/catalog.xml"/>
</fx:Declarations>
<mx:DataGrid id="dg"
dataProvider="{myDB}"
creationComplete="dg_creationCompleteHandler(event)">
<mx:columns>
<mx:DataGridColumn headerText="ProductId"
dataField="@productId"/>
<mx:DataGridColumn headerText="Name"
dataField="name"/>
<mx:DataGridColumn headerText="Price"
dataField="price"/>
<mx:DataGridColumn headerText="Series"
dataField="series"/>
</mx:columns>
</mx:DataGrid>
</s:Application>
Originally posted 2010-07-31 11:55:26.


