Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

Extracting Data from Nested XML Elements into Flex

alice_data
Level 2
Level 2
Hi,



I am a newbie and have just started using Flex. I have a
little XML that I created from PHP in the following:



<student>

<id>001</id>

<name>Test I</name>

<instructor_name>

<first_name>Tara</first_name>

<last_name>Morrison</last_name>

</instructor_name>

</student>



I used HTTPService provided by Flex to extract the data, and
I seem to have no issues extracting the first two columns. However,
When I got to the instructor_name, the datagrid gives me this on
the screen produced by the HTML: [object] [Object].



This is what I have in my Flex to extract this particular
element:

<mx:DataGridColumn headerText="Instructor Name"
dataField="instructor_name"/>



Does anyone have any tips on how I can get it to display Tara
Morrison in my actual result?



Anything is appreciated.



Alice
3 Replies
FlexPrashant
Level 2
Level 2
How do you are taking result of http serivce .. Means to say
as Array Collection or xml ... show me your code may be it will
help me to solve the problem
alice_data
Level 2
Level 2
Hi,



I have learned that the simplest way is to use the label
function in Flex, like the following:



private function lfnGeneral(item:Object,
column:DataGridColumn):String

{

var sLabel:String = ""

var sHeaderText:String = column.headerText; //so we can
handle the variables



switch (sHeaderText) {

case "ID":

sLabel=item.ois_id;

break;

case "Name":

sLabel=item.name;

break;

}

return sLabel;

}

Of course, the backdrop is that the name of the item has to
be the same as what appears in the rendered XML file from PHP or
any other programming language.
whertzing
Level 1
Level 1
Hmm.. I'm a newbie too, but looking at your XML, it seems the
<instructor_name> has no direct data, instead it has two
child nodes first_name and last_name. Seems you should calling a
function that accepts an object, passing it the
<Instructor_name> object, and in that function concatenating
the children data.



Check out the help section "Using item renderers with the
AdvancedDataGrid control", create and assign a renderer for your
<instructor_name> column, and concatenate the two name fields
inside of the renderer function.



Again, I'm a newbie myself, and I have not tried the
suggestion above, but I hope it points you toward a
solution.