You can do both.  Bottom line, the DataGrid requires a list of items.
This can be an XMLList or Array, ONLY if you are certain you will not
need to update the data items individually.  Best practice is to use an
XMLListCollection, which is a collection of XML nodes, or an
ArrayCollection of item value objects.  Each item in the collection
produces a row.

 

Given such a list of data items, each row of the DataGrid gets a
reference to the data item producing it. You specify which property or
attribute in the item goes in which column using the DataGridColumn
object.  If the value you want is in a top-level property of the item
(an attribute or first level child node of an XML item, or a top-level
property of the item object) you can specify the dataField.  It the
value you want is nested deeper in the item object, use labelFunction().

 

There are many examples available.

 

Tracy

 

________________________________

From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On
Behalf Of kenny14390
Sent: Friday, January 11, 2008 7:00 PM
To: flexcoders@yahoogroups.com
Subject: [flexcoders] Using an XML file as a dataProvider and accessing
its data

 

I started with Flex a couple days ago and I'm just learning the
basics. This shouldn't be too hard to answer, but getting me to
understand it would be the hard part! If I have an XML file with
parents, children, and siblings (see the example below), how can I
link say a DataGrid to a child element, but access its children? Refer
to the sample XML file below. Let's call it test.xml

<?xml version="1.0" encoding="utf-8"?>
<Schedule>
<Semester id='Spring08'>
<Department id='ACCT' name='Accounting'>
<Course id='211' name='Financial Accounting'>
<Section id='DIS01' limit='150' enroll='71'>
<Section id='ACT50' limit='25' enroll='8'/>
<Section id='ACT51' limit='25' enroll='12'/>
</Section>
<Section id='DIS02' limit='41' enroll='23'>
<Section id='ACT56' limit='41' enroll='23'/>
</Section>
</Course>
<Course ....>
<Section ...>
....
</Section>
</Course>
...
</Department>
...
</Semester>
...
</Schedule>

>From what I understand, one way to get this document into the DataGrid
is to create an HTTPService that connects to the XML file and give it
an id, we'll call it 'file'. So in the DataGrid we would say
"dataProvider='file.Schedule.Semester.Department.Course.Section'"? If
this is the case, how does the DataGrid know what attributes to pull
out of the elements and how is this displayed?

Let's say I want to do some OOP and make an object for every Semester,
Department, Course, and Section. How would I read this data and create
the objects? Fields of the objects would be equivalent to the
attributes to the elements. 

Thank you all for the support

 

Reply via email to