xpath: find child, where another child of the same node has specific value -


here xml:

 <cat>     <row>        <col attr="w">111</col>        <col attr="p">222</col>        <col attr="g">333</col>        <col attr="r">444</col>        <col attr="n1">555</col>        <col attr="n2">666</col>        <col attr="s">777</col>     </row>     <row>        <col attr="w">aaa</col>        <col attr="p">bbb</col>        <col attr="g">nnn</col>        <col attr="r">mmm</col>        <col attr="n1">xxx</col>        <col attr="n2">ccc</col>        <col attr="s">vvv</col>     </row> </cat>  

what for: find

 //cat/row/col[@attr='n2']

only , if in same parent node

//cat/row/col[@attr='w']==111

here's alternative solution consider more readable add conditions in each node of xpath expression go, without need use parent:

//cat/row[./col[@attr='w' , text()='111']]/col[@attr='n2'] 

with same output:

<col attr="n2">666</col> 

Comments

Popular posts from this blog

Change php variable from jquery value using ajax (same page) -

Pull out data related to my apps from Android Play Store and iOS App Store -

How can I fetch data from a web server in an android application? -