PDA

View Full Version : xml in datagrid


sebi_barzeianu
07-25-2009, 04:25 PM
Hi there!

I just started working with Adobe Flex 3, and I am trying simply to list some data from an xml file into a datagrid.

here's my code:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute">

<mx:XML id="tempXML"
source="luci.xml"/>
<mx:XMLListCollection id="myXMLList"
source="{tempXML.id}"/>
<mx:DataGrid id="dataGrid"
dataProvider="{myXMLList}"
width="100%"
rowCount="{myXMLList.length}">
<mx:columns>
<mx:DataGridColumn dataField="id"
headerText="Friends:"/>
</mx:columns>
</mx:DataGrid>
</mx:Application>



and this is the luci.xml file I am using:

<?xml version="1.0" encoding="UTF-8"?>
<ids>
<id>15302864zzz</id>
<id>21781202</id>
<id>7560872</id>
<id>47354508</id>
<id>54888349</id>
<id>56077396</id>
<id>42290523</id>
<id>22391927</id>
<id>36313301</id>
<id>22394041</id>
</ids>


when I run the code, all I get is an empty datagrid, but it has exactly 10 rows corresponding to my ids in the file (I think).

Can anyone tell me what is wrong with my code?

Thank you

Peter Cowling
07-25-2009, 05:07 PM
Hi,


<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute">

<mx:XML id="tempXML"
source="luci.xml"/>
<mx:XMLListCollection id="myXMLList"
source="{tempXML.ids}"/>
<mx:DataGrid id="dataGrid"
dataProvider="{myXMLList}"
width="100%"
rowCount="{myXMLList.length}">
<mx:columns>
<mx:DataGridColumn dataField="id"
headerText="Friends:"/>
</mx:columns>
</mx:DataGrid>
</mx:Application>



<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<Luci>

<ids>
<id>Friend1</id>
</ids>

<ids>
<id>Friend2</id>
</ids>

<ids>
<id>Friend3</id>
</ids>
</Luci>


EDIT
Revised XML

sebi_barzeianu
07-25-2009, 06:07 PM
Ok, I can see the values now. It seems strange that all of them appear to be in the same row (the same cell of the grid). Also, they are listed with <Id> and </Id> tags.
How can I display them without the tags and in different rows?

I would also like to ask you to direct me to a good example of how to load xml files using URLLoader.

Thank you for your time.

Peter Cowling
07-25-2009, 08:32 PM
Hi,

Revised xml, which will work fine this time around. Will post on URLLoader t'row if no one has by then.