--- In [email protected], "Derrick Grigg" <[EMAIL PROTECTED]> wrote:
>
> I ran into a similar problem when using xml data returned from a web
> service. You need to either use the wildcard namespace or declare
> and add one on to the result. I found it easier just to use the
> wildcard.
>
> myCollection.*::source.*::trainingEvent.*::trainingEventInstance.*::
> (@keyID == instanceID).parent()[EMAIL PROTECTED];
>
> or something to that effect should do the trick
>
> http://livedocs.macromedia.com/flex/2/docs/wwhelp/wwhimpl/js/html/wwh
> elp.htm?href="">>
> Derrick Grigg
> -------------
> www.dgrigg.com
>
> --- In [email protected], "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!
> >
>
Hi, find here pls a little snippet highlighting the fact that XMLListCollection implements
ICollectionView . We can then navigate in it using IViewCursor.
<?xml version="1.0"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" initialize="initCursor()">
<mx:Script>
<![CDATA[
import mx.collections.IViewCursor;
import mx.controls.Alert;
import mx.controls.TextArea;
[Bindable]
public var myCursorStr:String;
public var myXMLList:XMLList;
public var myXMLList2:XMLList;
public var myXMLList3:XMLList;
public var myCursor:IViewCursor;
//------------------------------------------------------------------------------------------------
//We'd like to get the label attribute of this xml object's parent. (Canadian Province Capitals)
//------------------------------------------------------------------------------------------------
public var myXml:XML = <capital label="BC" value="Victoria"/>;
public function initCursor():void {
myCursor=capitalColl.createCursor();while (myCursor.moveNext()) {
myXMLList = XMLList(myCursor.current);
//got one Capitals, run through its children
myXMLList2=myXMLList.children();
var cont:Boolean=myXMLList2.contains(myXml);
if (cont) break;
}
//build some logic here
myXMLList3= myXMLList.
attribute("label");myCursorStr=myXMLList3.toXMLString();
}
]]>
</mx:Script>
<mx:XML id="capitals">
<root>
<Capitals label="U.S. State Capitals">
<capital label="AL" value="Montgomery"/>
<capital label="AK" value="Juneau"/>
<capital label="AR" value="Little Rock"/>
<capital label="AZ" value="Phoenix"/>
</Capitals>
<Capitals label="Canadian Province Capitals">
<capital label="AB" value="Edmonton"/>
<capital label="BC" value="Victoria"/>
<capital label="MB" value="Winnipeg"/>
<capital label="NB" value="Fredericton"/>
</Capitals>
</root>
</mx:XML>
<!-- Create an XMLListCollection representing the Tree nodes.
capitals.Capitals is an XMLList with both Capitals elements. -->
<mx:XMLListCollection id="capitalColl" source="{capitals.Capitals}"/>
<mx:TextArea id="mt" width="200" height="200" text="{myCursorStr}"/>
</mx:Application>
good luck, Bela
--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com
| Software development tool | Software development | Software development services |
| Home design software | Software development company |
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
__,_._,___

