want to refer to some cousin child value in xml path -


this xml doc

 <ct>   <child 1>  10   </child 1>   <child 2>   20    </child 2>  </ct>    <th>     <child 3> 100   </child 3>     <child 4> 200   </child 4>  </th>    <ct>   <child 1>  30  </child 1>   <child 6>  40  </child 6>  </ct>    <th>     <child 7>  300  </child 7>     <child 8>  400  </child 8>  </th> 

i want fetch value 30 have used following xpath root/parent/th../ct/child1

i cannot change root/parent/th fixed according requirements can change rest of xpath starting ../ct/child1

you have error in xpath expression: not /th../ /th/../

also, /root/parent/th selects 2 th elements , it's not clear 1 should used because both of them have preceding ct child1 child.

straightforward answer is

/root/parent/th[last()]/preceding-sibling::ct[1]/child1 

i.e. first preceding sibling element ct of last th.

but more useful answer need more info.


Comments

Popular posts from this blog

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -

qt - How to embed QML toolbar and menubar into QMainWindow -