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


 
On 10/4/06, Clare Todd <[EMAIL PROTECTED]> 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





SPONSORED LINKS
Software development tool Software development Software development services
Home design software Software development company

Your email settings: Individual Email|Traditional
Change settings via the Web (Yahoo! ID required)
Change settings via email: Switch delivery to Daily Digest | Switch to Fully Featured
Visit Your Group | Yahoo! Groups Terms of Use | Unsubscribe

__,_._,___

Reply via email to