Tracy,
Thanks for the heads up. I found your article on cflex.net and
updated the code to work in Flex 2.0
Here are the modifications:
Set the resultEvent of the httpService to an XML object instead of an
XMLNode
###############################################################
private function resultHandler(event:ResultEvent):void{
myXML = event.result as XML;
}
In the datagrid, set the datasource property to myXML.employee
#############################################################
dataProvider="{myXML.employee}"
LabelFunction passes two arguments now instead of one
#############################################################
<mx:DataGridColumn headerText="Name"labelFunction="getLabelLastName"/>
private function
getLabelLastName(item:Object,column:DataGridColumn):String
{
return item.name.lastname;
}
Thanks again for all your help. I had been spinning my wheels on this
one.
-mat
--- In [email protected], "Tracy Spratt" <[EMAIL PROTECTED]> wrote:
>
> Yes. To use the DataField property, the data must be a first level
> property of the dataProvider item, as is the street node. Firstname,
> however is another level deep in the xml.
>
>
>
> You wil need to use a labelFunction() instead of the dataField. Check
> this out in the docs, and search for it on cflex.net. Post back if you
> still have troubles.
>
>
>
> Tracy
>
>
>
> ________________________________
>
> From: [email protected] [mailto:[EMAIL PROTECTED] On
> Behalf Of matmls
> Sent: Monday, January 29, 2007 4:37 PM
> To: [email protected]
> Subject: [flexcoders] Accessing nested xml tag using e4x and httpService
>
>
>
> Below is a sample of my xml file:
>
> <employee id="2" type="part-time">
> <name>
> <firstname>Ann</firstname>
> <lastname>Jones</lastname>
> </name>
> <street>52 Cove Court</street>
> </employee>
>
> I can return results with httpService :
>
> <mx:HTTPService
> id="srv"
> url="employee.xml"
> resultFormat="e4x"
> result="resultHandler(event);"
> fault="faultHandler(event);"
> />
>
> I can then access the values in the street tag, but NOT firstname or
> lastname in a datagrid:
>
> <mx:DataGrid dataProvider="{srv.lastResult.employee}">
> <mx:columns>
> <mx:DataGridColumn headerText="Name" dataField="name.firstname"/>
> <mx:DataGridColumn headerText="Street" dataField="street"/>
> </mx:columns>
> </mx:DataGrid>
>
> Is there a syntax problem with the way I am attempting to access
> firstname and lastname? I am able to populate an xml object and
> access firstname and lastname with:
>
> myXML.employee.name.lastname
>
> Thanks in advance for any assistance.
>