Search code examples
xmlactionscript-3conditional-statementsdescendant

AS3: Descendants with multiples conditions


Example of my XML list:

<listnode>
   <nodeA id="1">
       <nodeB id="1" />
   </nodeA>
   <nodeA id="2">
       <nodeB id="2" />
   </nodeA>
</listnode>

<listnode>
   <nodeA id="2">
       <nodeB id="2" />
   </nodeA>
   <nodeA id="1">
       <nodeB id="3" />
   </nodeA>
   <nodeA id="5">
       <nodeB id="1" />
   </nodeA>
</listnode>

<listnode>
    ... etc

I'm trying to get an XML list based on multiple conditions. With one condition, it's fine, using something like:

var  list:XMLList = list.(descendants("nodeA").@id.contains("1"));

This gives me a list of all the listnode in list that have any descendant named nodeA with an attribute id=1.

How can I retrieve the same list, but looking also for the id of the nodeB nodes? Something like:

var  list:XMLList = list.(descendants("nodeA").@id.contains("1") && nodeA.descendants("nodeB").@id.contains("3"));

In this example, that should give me a list with one node:

<listnode>
   <nodeA id="2">
       <nodeB id="2" />
   </nodeA>
   <nodeA id="1">
       <nodeB id="3" />
   </nodeA>
   <nodeA id="5">
       <nodeB id="1" />
   </nodeA>
</listnode>

Because it has a nodeA with id=1 who has a nodeB with id=3.

Any ideas?


Solution

  • UPDATED

    list.(descendants("nodeA").(@id.contains("1") && descendants("nodeB").@id.contains("3")).length() > 0)
    

    What about this?