Daniel said "but length doesn't do it" without mentioning what it gave
him (Probably undefined.) I suspect the problem is that he said
match.length instead of match.length(). The length() of the <matches>
element would always be 1, because there is always exactly one <matches>
element, but the length() of the <match> element should give him the
number of <match> elements inside <matches>, which might be 0, 1, or
more.

 

- Gordon

 

________________________________

From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On
Behalf Of Lachlan Cotter
Sent: Wednesday, November 29, 2006 4:50 AM
To: flexcoders@yahoogroups.com
Subject: Re: [flexcoders] Built-in way to determine the number of XML
elements

 

Why don't you just test the length of the matches element?

 

<?xml version="1.0" encoding="utf-8"?>

<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml
<http://www.adobe.com/2006/mxml> " layout="absolute"
creationComplete="output()">

            <mx:Script>

                        <![CDATA[

 

                                    [Bindable]

                                    private var xml1:XML = <root>

 
<matches/>

                        </root>;

              

               [Bindable]            

              private var xml2:XML = <root>

                                  <matches>

                                      <match/>

                                  </matche! s>

                        </root>;

              

              private function output ():void

              {

          r1.text =
XML(xml1.matches).child('match').length().toString();

                   r2.text = XML(xml2.matches!
).child('match').length().toString();

              }

              

     ]]>

     </mx:Script>

     

     <mx:VBox>

     

          <mx:Label text="First Result"/>

          <mx:TextInput id="r1"/>

          

          <mx:Label text="Second Result"/>

          <mx:TextInput id="r2"/>

          

     </mx:VBox>

          

</mx:Application>

 

! 

 

On 29/11/2006, at 7:56 AM, Daniel Thompson wrote:





I'm trying to see if a response from the server is empty. So, in one
case I
end up with:

<root>
<matches/>
</root>

And in the other, I get:

<root>
<matches>
<match ... />
</matches>
</root>

Using this fancy E4X, how do I test for the different conditions? I
always
seem to be getting back an XMLList, be it empty or not. I can't imagine
I
have to iterate this and check that it's zero at the end, ! but length
doesn't
do it, and I can't check for null because I'm always getting an XMLList.

Thanks,
-DT

 

 

 

Reply via email to