Flex, Getting XML attributes values.

If the XML format is like :

<root>

<banana>

<apple>

<description language=”EN” title=”title EN” id=”1″>Hello</description>

<description language=”DE” title=”title DE” id=”1″>Hello 2</description>

</apple>

<apple>

<description language=”EN” title=”title EN” id=”1″>Hello</description>

<description language=”DE” title=”title DE” id=”1″>Hello 2</description>

</apple>

</banana>

<apple>

<description language=”EN” title=”title EN” id=”1″>Hello</description>

<description language=”DE” title=”title DE” id=”1″>Hello 2</description>

</apple>

</root>

then….to parse title attribute value….do the following things:

<mx:Application xmlns:mx=http://www.adobe.com/2006/mxml initialize=”LoadXML();”>

<mx:XML id=”urlPath” source=”assets/xmlfile.xml”/>

</mx:Application>

[Bindable]

private var fruitsArray:ArrayCollection = new ArrayCollection();

public function LoadXML():void{

//Alert.show(“fruits====”+urlPath..apple.length());

for(var i:int;i < urlPath.banana.apple.length();i++){

var appleString:String = urlPath.banana.apple[i].description[0].@title;

fruitsArray.addItemAt({fruitsTitle:appleString},i);

}

}

<mx:DataGrid dataProvider=”{fruitsArray}” width=”100%” height=”100%” verticalGridLines=”false”>

<mx:columns>

<mx:DataGridColumn headerText=”Fruits” dataField=”fruitsTitle” />

</mx:columns>

</mx:DataGrid>

 

 

 

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s


Follow

Get every new post delivered to your Inbox.