Thanks for the reply. I'm wondering why I can't? According to the docs, "myCollection.source" gived an XMLList, and the XMLList docs say that "This class (along with the XML, Namespace, and QName classes) implements powerful XML-handling standards defined in ECMAScript for XML (E4X) specification (ECMA-357 edition 2)."
I'm unfortunately in the process of trying to figure out how to use XML as a datasource (from a PHP page) and effectively use it to manage data throughout my Flex app. I thought the whole point of e4x was to NOT have to iterate through everything? Let me go about this a different way and see if anyone has a better idea for how to handle all of this information. I have XML coming down from php. The PHP is grabbing itfrom a relational database, where there is a table of trainingEvents (with unique keyID's) and a table of trainingEventInstances, which are many to 1 with the events. Some of the instances can override certain properties like price... <catalog> <trainingEvent keyID="1" title="Programming 101" eventCost="499.99"> <trainingEventInstance keyID="1" location="Houston" eventDate="02/11/2007" instanceCost="499.99" /> <trainingEventInstance keyID="2" location="Houston" eventDate="04/19/2007" instanceCost="499.99" /> <trainingEventInstance keyID="3" location="Las Vegas" eventDate="04/19/2007" instanceCost="299.99" /> </trainingEvent> <trainingEvent keyID="2" title="Miter Saw Safety" eventCost="300.00"> <trainingEventInstance keyID="4" location="Houston" eventDate="12/25/2006" instanceCost="300.00" /> </trainingEvent> <trainingEvent keyID="3" title="How to Fly The Shuttle" eventCost="19.99"> <trainingEventInstance keyID="5" location="Florida" eventDate="09/01/2007" instanceCost="1499.99" /> <trainingEventInstance keyID="6" location="Nevada" eventDate="12/10/2006" instanceCost="499.99" /> <trainingEventInstance keyID="7" location="India" eventDate="11/24/2006" instanceCost="19.99" /> </trainingEvent> </catalog> I want to do the following things with it: 1. Display the structure in a tree, where there are trainingEvents at the topmost level, with their instances below them. (I'm doing this currently by putting the XML into an XMLListCollection and using it as the source for a tree, with label and icon functions. Works well). 2. Be able to drag and drop trainingEventInstances onto a Person (items in a listbox ) and have those trainingEventInstances assigned to them. 3. Show a datagrid of the titles, locations, and dates for any person's assignments. The problem I keep hitting is when I want to display the titles. The title is a property of the trainingEvent, not the trainingEventInstance... I could solve it by adding the title to the instances, but that seems like a lot like duplicating data to me. I would have assumed that I could, at any time, find the instance I need in the structure, go to its parent, and grab the title? The "traverse all nodes" method will work, but what when I have 1000 items in my catalog and the person is assigned to 100 of them. My label function in the datagrid would be going 100,000 loops to print the titles, which seems wrong. Can anyone tell me of a way to work with data coming from a relational database so that I can display relevant info as I need it? Thanks! -- TC --- In flexcoders@yahoogroups.com, "Prakaz" <[EMAIL PROTECTED]> wrote: > > I'm not sure if you will be able to directly access the trainingEvent > title using the return statement you have given below. Looking at the > structure of the XML, it seems inevitable that you'll have to iterate > through each and every node to search for the KeyID you are looking for > and when you find one grab the title from the parent node. Here is a > code that works: the XML: <mx:XML id="theCatalog"> > <catalog> > <trainingEvent keyID="1" title="Programming 101" eventCost="499.99"> > <trainingEventInstance keyID="1" trainingEventID="1" > location="Houston" eventDate="02/11/2007" instanceCost=" 499.99" /> > <trainingEventInstance keyID="2" trainingEventID="1" > location="Houston" eventDate="04/19/2007" instanceCost="499.99" /> > <trainingEventInstance keyID="3" trainingEventID="1" location="Las > Vegas" eventDate="04/19/2007" instanceCost=" 299.99" /> > </trainingEvent> > <trainingEvent keyID="2" title="Miter Saw Safety" eventCost="300.00"> > <trainingEventInstance keyID="4" trainingEventID="2" > location="Houston" eventDate="12/25/2006" instanceCost=" 300.00" /> > <trainingEventInstance keyID="5" trainingEventID="2" > location="Houston" eventDate="12/25/2006" instanceCost="300.00" /> > <trainingEventInstance keyID="6" trainingEventID="2" > location="Houston" eventDate="12/25/2006" instanceCost=" 300.00" /> > <trainingEventInstance keyID="7" trainingEventID="2" > location="Houston" eventDate="12/25/2006" instanceCost="300.00" /> > </trainingEvent> > </catalog> > </mx:XML> public function getCourseTitle(instanceID:Number){ > // Iterate through each Node of the XML > for each(var parentNodes:XML in theCatalog.trainingEvent){ > var childNodes:XMLList=parentNodes.trainingEventInstance; > > // Iterate through each Child Node of the XML > for each(var individualChild:XML in childNodes){ > if([EMAIL PROTECTED]){ // Found the bastard :-) > // Return title of the parent > return [EMAIL PROTECTED]; > } > } > } > } > Usage: > if you call getCourseTitle(4) you'll get "Miter Saw Safety" and so on... > hope that helps, Prakaz > > --- In flexcoders@yahoogroups.com, "Clare Todd" <clare_todda@> wrote: > > > > I have a hunk of XML that I have loaded into an XMLListCollection. It > describes a training course catalog. I'm trying to write a function to > return the title of a course when passed the "KeyID" of a specific > course instance, and am running into all sorts of problems (it ain't > working being the worst of them). > > > > Here's the XML: > > > > <catalog> > > <trainingEvent keyID="1" title="Programming 101" eventCost="499.99"> > > <trainingEventInstance keyID="1" trainingEventID="1" > location="Houston" eventDate="02/11/2007" instanceCost="499.99" /> > > <trainingEventInstance keyID="2" trainingEventID="1" > location="Houston" eventDate="04/19/2007" instanceCost="499.99" /> > > <trainingEventInstance keyID="3" trainingEventID="1" location="Las > Vegas" eventDate="04/19/2007" instanceCost="299.99" /> > > </trainingEvent> > > <trainingEvent keyID="2" title="Miter Saw Safety" eventCost="300.00"> > > <trainingEventInstance keyID="4" trainingEventID="2" > location="Houston" eventDate="12/25/2006" instanceCost="300.00" /> > > </trainingEvent> > > </catalog> > > > > ... it's loaded into an XMLListCollection called myCollection using > HTTP service with resultFormat=e4x > > > > I'm trying to ignore the trainingEventID attribute, since it might be > going away. I was trying to do some e4x magik to find the title like > this, where the parameter is the KeyID of the trainingEventInstance: > > > > public function getCourseTitle( instanceID:Number ):String { > > return myCollection.source.trainingEvent.trainingEventInstance.(@keyID > == instanceID).parent()[EMAIL PROTECTED]; > > } > > > > so when the function is passed 4, it returns "Miter Saw Safety" > > > > Am I doing something wrong? Can I not e4x using the "source" property? > Any thoughts? Thanks! > > > -- 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/ <*> Your email settings: Individual Email | Traditional <*> To change settings online go to: http://groups.yahoo.com/group/flexcoders/join (Yahoo! ID required) <*> To change settings via email: mailto:[EMAIL PROTECTED] mailto:[EMAIL PROTECTED] <*> 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/