views:

203

answers:

2

Ok- here's a painfully easy one I bet --

I'm aware of how to use EX4 to filter most pieces of the xml I need

  • however how can I filter an XML list such as the one below to check say --- if a dog is a beagle? preferably as a Boolean.

var theXml:XML =

 <animals>
   <animal dog ="poodle" cat="Siamese" />
   <animal dog ="beagle" cat="calico" />
   <animal dog ="mutt" cat="tabby" />    
 </animals>   

var animalList:XMLList = theXml.animals.animal;


this ended up working ( thanks Tyler )...

if (theXml.animals.animal.(@dog == "beagle").length > 0) {
    trace('match')
}

thanks ! -MW

+1  A: 

Hi there,

I love the power of E4X, here's the example of what you are looking for:

theXml.animals.animal.(@dog == 'beagle');

If it finds a match it'll return it.

EDIT

To answere your question below:

var xml:XML = <a id="34"></a>;

//traces
if (xml.(@id == '34').length() != 0) {
    trace('match')
}

//no trace
if (xml.(@id == '35').length() != 0) {
    trace('match')
}
Tyler Egeto
thanks... hmmm -- so how would I use it -- see altered example above " //both of these return true "
MW
Updated my response above with example. Goodluck!
Tyler Egeto
To understand why your trace shows nothing, look into the toString() method on XML objects, it behaves a little funny, and not how you might expect.
Tyler Egeto
thanks Tyler - got it working great with that :) -MW
MW
A: 

You shouldn't need the root node "animals":

theXml.animal.(@dog == 'beagle');
Dave Stewart