views:

74

answers:

1

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

+1  A: 

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

phwd
thanks buddy it worked
Mirage