Search code examples
xmlxpathnodeschild-nodesparent-node

how to get a value inside a child node without giving parent node in a xpath


I have a xml that looks like this

<req>
  <info>
  <element name = "bob" value="20"/>
  <element name = "reena" value="50"/>
  </info>
</req>

I need to get value 20 or 50 without using parent nodes req and info

can anyone help me with this?


Solution

  • You might find something like

    number(//element[@name="reena"]/@value)
    

    a bit more flexible.