something like this gets the job done but i think there are better ways
<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml"; 
layout="absolute" creationComplete="initApp()" >
<mx:Script>
<![CDATA[
import mx.controls.dataGridClasses.DataGridColumn;
[Bindable]
private var myXML:XML = <xmldata>
<structure>
<header>Name</header>
<header>Address</header>
<header>Phone</header>
</structure>
<contact>
<data>Joe Doe</data>
<data>Anywhere USA</data>
<data>555-555- 5555</data>
</contact>
<contact>
<data>Joe Doe</data>
<data>Anywhere USA</data>
<data>555-555- 5555</data>
</contact>
</xmldata>
private function initApp():void{
}
private function myXMLTest(value:Object,column:DataGridColumn):String{
if(column.headerText=="Name"){
return myXML..data[0];
}else{
if(column.headerText=="Address"){
return myXML..data[1];
}else{
return myXML..data[2];
}
}
}
]]>
</mx:Script>
<mx:DataGrid dataProvider="{myXML.contact}" id="myDataGrid">
<mx:columns>
<mx:DataGridColumn labelFunction="myXMLTest" 
headerText="{myXML.structure.header[0]}"/>
<mx:DataGridColumn labelFunction="myXMLTest" 
headerText="{myXML.structure.header[1]}"/>
<mx:DataGridColumn labelFunction="myXMLTest" 
headerText="{myXML.structure.header[2]}"/>
</mx:columns>
</mx:DataGrid>



----- Original Message ----
From: atlas1j <[EMAIL PROTECTED]>
To: flexcoders@yahoogroups.com
Sent: Tuesday, January 29, 2008 10:52:09 AM
Subject: [flexcoders] Re: xml data in a datagrid

Ugh, many thanks for the reply, but I don't have control over the xml 
feed that I was hoping to display. :-/ I had hoped flex would be 
flexible enough to accomodate this easily. 

--- In [EMAIL PROTECTED] ups.com, Sherif Abdou <[EMAIL PROTECTED] ..> wrote:
>
> you would at least need to change the xml for these to work i think
> so 
> 
> <data1>Joe Doe</data1>
> <data2>Anywhere USA</data2>
> <data3>555-555- 5555</data3>
> 
> <mx:DataGrid dataProvider= "{myXML}" >
> <mx:columns>
> <mx:DataGridColumn dataField="{ myXML.contact. data}" 
headerText=" {myXML.structure .data}"/>
> </mx:columns>
> </mx:DataGrid>
> 
> 
> ----- Original Message ----
> From: atlas1j <[EMAIL PROTECTED] >
> To: [EMAIL PROTECTED] ups.com
> Sent: Tuesday, January 29, 2008 10:12:48 AM
> Subject: [flexcoders] xml data in a datagrid
> 
> This is probably simple for those that aren't flex newbies but my 
> flex books haven't arrived yet from Amazon and I am getting 
confused 
> by reading and searching on the web. What I have are xml document 
> that I don't control that describe their own structure. See the 
> simplified sample below:
> 
> <xml>
> <adml version="0">
> 
> <structure>
> <header>Name< /header>
> <header>Address< /header>
> <header>Phone< /header>
> </structure>
> 
> <contact>
> <data>Joe Doe</data>
> <data>Anywhere USA</data>
> <data>555-555- 5555</data>
> </contact>
> 
> <contact>
> <data>Joe Doe</data>
> <data>Anywhere USA</data>
> <data>555-555- 5555</data>
> </contact>
> 
> I want to make the <structure> elements the data grid column 
headers 
> and have each of the <data> items rendered in the correct column. 
> Can anyone provide a pointer as to how to proceed? Thanks!
> 
> 
> 
> 
> 
> 
____________ _________ _________ _________ _________ _________ _
____________ __
> Looking for last minute shopping deals? 
> Find them fast with Yahoo! Search. 
http://tools. search.yahoo. com/newsearch/ category. php?category= shopping
>





      
____________________________________________________________________________________
Never miss a thing.  Make Yahoo your home page. 
http://www.yahoo.com/r/hs

Reply via email to