开发者

AS3: Descendants with multiples conditions

开发者 https://www.devze.com 2023-02-27 13:14 出处:网络
Example of my XML list: <listnode> <nodeA id=\"1\"> <nodeB id=\"1\" /> </nodeA> <nodeA id=\"2\">

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 a开发者_JAVA技巧ttribute 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?


UPDATED

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

What about this?


Yes, conditions can be combined.

var list: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>
</list>;
var result:XMLList = list.listnode.descendants("*").(@id=="1" && children().length() > 0); 
0

精彩评论

暂无评论...
验证码 换一张
取 消