When you trace out:

trace(staff.*.(POSITION == "Designer"));

You will see that it returns the parent <EMPLOYEE> element... So, even
if your code were to work, all it would do would be to return the root
<STAFF> node, which probably wouldn't help you.

If you compare the two examples, you will see that there is only one
<POSITION> node within each <EMPLOYEE> node...

If you modify the staff XML to be:

   var staff:XML = <STAFF>
        <EMPLOYEE ID="501" HIRED= "1090728000000">
           <NAME>Marco Crawley</NAME>
           <MANAGER>James Crawley</MANAGER>
           <POSITION>Designer</POSITION>
           <POSITION>Programmer</POSITION>
        </EMPLOYEE>
 </staff>

It will no longer work.

Also, you should be using attributes as opposed to entering values
directly into nodes. I personally never filter e4x through the node
value, but rather through attribute values, like so...

var staff2:XML=<STAFF>
        <EMPLOYEE name="fred">fred</EMPLOYEE>
        <EMPLOYEE name="bob">bob</EMPLOYEE>
        <EMPLOYEE name="leroy">leroy</EMPLOYEE>
        <EMPLOYEE name="algernon">algernon</EMPLOYEE>
</STAFF>

 trace("find leroy: " +staff2.*.(@name=="leroy").toXMLString());


Hope this helps.

- Taka

On Thu, Feb 19, 2009 at 5:22 PM, Ferd Berfel <[email protected]> wrote:
> hello,  newbie here...
>
>
> I'm trying to understand searching xml with e4x
>
> why does this work:
>
>    var staff:XML = <STAFF>
>         <EMPLOYEE ID="501" HIRED= "1090728000000">
>            <NAME>Marco Crawley</NAME>
>            <MANAGER>James Crawley</MANAGER>
>            <POSITION>Designer</POSITION>
>         </EMPLOYEE>
>  </staff>
>
> var results:XMLList= staff.*.(POSITION == "Designer")
>
> and this does not?
>
> var staff2:XML=<STAFF>
>  <EMPLOYEE>fred</EMPLOYEE>
>  <EMPLOYEE>bob</EMPLOYEE>
> <EMPLOYEE>leroy</EMPLOYEE>
> <EMPLOYEE>algernon</EMPLOYEE>
> </STAFF>
>
>  trace("find leroy: " +staff2.(EMPLOYEE=="leroy"));
>
> but more importantly, how WOULD I find leroy?  (I know I can create a
> function to loop through children, but I'm wondering how to do it within the
> format describe)
>
>
> tia
> ferd
> _______________________________________________
> Flashcoders mailing list
> [email protected]
> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
>
_______________________________________________
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Reply via email to