HOw to find specific child node in XML using AS3 flash
I have this xml
var testXML:XML = <family>
<father name1="tom" age="5" ><father1 name1="test1"/><father2 name1="test2"/></fat开发者_StackOverflowher>
<mother name1="tomylee" age="55" ><mother1/><mother2/></mother>
<sister name1="sister1" age="35" ><sister1/><sister2/></sister>
</family>;
I want to get the child node with name1 = test1 but i only know family
so is there something like
trace (testXML.children(@name1="test1");
I only know the family node , i don't know where that node is inside the father or not
is there any filter can be applied on root node to find something
Use the hasOwnProperty and some logical operators
trace( testXML..*.( hasOwnProperty("@name1") && @name1 == "tom" ));
trace( testXML..*.( hasOwnProperty("@name1") && @name1 == "test1" ));
I modified your XML to at least show a result
var testXML:XML = <family>
<father name1="tom" age="5" ><father1 name1="test1">father1</father1><father2 name1="test2"/></father>
<mother name1="tomylee" age="55" ><mother1/><mother2/></mother>
<sister name1="sister1" age="35" ><sister1/><sister2/></sister>
</family>;
Trace for proof
<father name1="tom" age="5">
<father1 name1="test1">father1</father1>
<father2 name1="test2"/>
</father>
UPDATE: -----THIS HERE --> .* <--is the wildcard to grab all items in the testXML
精彩评论