I use the XMLObjectOutput class (which you can find in the C:\Program
Files\Macromedia\Flex\extras\XMLObjectOutput directory (I just put it in
my user_classes directory in my own package) and I convert the XML from
the server into an object...by using this utility you can then use
dot-synatx to reference elements in your XML...
So, you can then do something like:
var xmlObjOut:XMLObjectOutput = new XMLObjectOutput(false);
var xml2Obj:Object = xmlObjOut.XMLToObject(yourXMLFromServer);
var items:Array = xml2Obj.Items;
// you now have an array of all items, so loop through all your Items
elements to get the child Item elements and add their status to the
datagrid
for (var i = 0; i < items.length; i++) {
var row:Object = new Object();
row["id"] = items[i].attributes.Id;
row["Title"] = items[i].attributes.Title;
row["Status"] = items[i].Status.attributes.Name;
gridStory.addItem(row);
}
And if you have your dataGrid described below with all the columns you
have set up below (minus the last one), this should work for you. Maybe
call the code above in a method upon creationComplete of datagrid or
most likely, on result of the service that returns the XML you're trying
to use to populate your datagrid.
Hope that helps.
robert l. brueckmann
senior web developer
merlin securities
595 madison avenue
new york, ny 10022
p: 212.822.4821
f: 212.822.4820
-----Original Message-----
From: [email protected] [mailto:[EMAIL PROTECTED] On
Behalf Of flexcoder1
Sent: Tuesday, July 12, 2005 10:22 AM
To: [email protected]
Subject: [flexcoders] display nested xml in a datagrid
Hi. Can someone help with this question? It is driving me crazy!
(the entire example is at the bottom of this post)
There is more to this problem but I have tried to simplify it to the
basic question below:
Say I have the following xml:
<?xml version="1.0" encoding="UTF-8"?>
<Items>
<Item Id="1" Title="Title1">
<Status Id="1" Name="Active" />
</Item>
<Item Id="2" Title="Title2">
<Status Id="2" Name="Inactive" />
</Item>
</Items>
How can I display the current status name of each item in a data
grid?
I have tried:
<mx:DataGrid id="gridStory" dataProvider="{mx.utils.ArrayUtil.toArray
( GetItems.result.Items.Item)}" width="100%" height="100%">
<mx:columns>
<mx:Array>
<mx:DataGridColumn columnName="Id" />
<mx:DataGridColumn columnName="Title" />
<mx:DataGridColumn columnName="Status" /> shows object
Object - I want the item's Status.Name to appear
<mx:DataGridColumn columnName="Status.Name" /> **** THIS
DOES NOT WORK ****
</mx:Array>
</mx:columns>
</mx:DataGrid>
How can I show the status? If I just use
<mx:DataGridColumn columnName="Status" />
the grid displays (as expected) object Object. Also, for this
particular xml file it is not an option to just collapse the Status
subtags into the Item tag and have something like:
<Item Id="2" Title="Title2" StatusId="2" StatusName="Inactive" />
*** For reasons outside scope of question I cannot do this ***
I know the above works correctly.
Thanks for any help with this. Below is the entire example:
test.mxml
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.macromedia.com/2003/mxml">
<mx:Model id="modItems" source="simple.xml">
</mx:Model>
<mx:DataGrid id="gridStory" dataProvider="{modItems.Item}"
width="100%" height="100%">
<mx:columns>
<mx:Array>
<mx:DataGridColumn columnName="Id" />
<mx:DataGridColumn columnName="Title" />
<mx:DataGridColumn columnName="Status" />
<mx:DataGridColumn columnName="Status.Name" />
</mx:Array>
</mx:columns>
</mx:DataGrid>
</mx:Application>
simple.xml
<?xml version="1.0" encoding="utf-8"?>
<Items>
<Item Id="1" Title="Title1">
<Status Id="1" Name="Active" />
</Item>
<Item Id="2" Title="Title2">
<Status Id="2" Name="Inactive" />
</Item>
</Items>
Thanks for any help.
--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives:
http://www.mail-archive.com/flexcoders%40yahoogroups.com
Yahoo! Groups Links
--------------------------------------------------------
This message contains information from Merlin Securities, LLC, or from one of
its affiliates, that may be confidential and privileged. If you are not an
intended recipient, please refrain from any disclosure, copying, distribution
or use of this information and note that such actions are prohibited. If you
have received this transmission in error, please notify the sender immediately
by telephone or by replying to this transmission.
Merlin Securities, LLC is a registered broker-dealer. Services offered through
Merlin Securities, LLC are not insured by the FDIC or any other Federal
Government Agency, are not deposits of or guaranteed by Merlin Securities, LLC
and may lose value. Nothing in this communication shall constitute a
solicitation or recommendation to buy or sell a particular security.
--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/flexcoders/
<*> To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/