views:

313

answers:

2

Hi,

Here is an XML:

<nodes>
     <node id="0" a="hello" b="this"/>
     <node id="1" c="is" d="a" e="test"/>
</nodes>

Is there a way, using E4X Filtering to find the node(s) who has an attribute with "this" as value ?

A: 
myXML.node.(@b == "this")

The above should work, though if you mean any attribute, then I think you have look through it youself. Though you could do it with regex then.

Lillemanden
yes i would like to filter on any attribute...i already have a workin solution, i was just looking for a quicker one...
OXMO456
Then no, I am fairly sure that is not posible.
Lillemanden
+2  A: 

You could try with something like this:

xml.node.( find(attributes(), "this") );
function find(atts:XMLList, value:String):Boolean {
    for each(var a in atts) if(a==value) return true;
    return false;
}

But I personally think that a simple loop to assemble a new XMLList is easier to understand, hence a better code practice... Complex E4X and RegEx are very hard to follow, and when they don't present considerable better performance than simpler solutions (i.e. loops), I don't think they should be used...

Cay