Reputation:
I have this xml
var testXML:XML = <family>
<father name1="tom" age="5" ><father1 name1="test1"/><father2 name1="test2"/></father>
<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
Upvotes: 2
Views: 3258
Reputation: 19995
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
Upvotes: 2