I need to get va" /> I need to get va" /> I need to get va"/>

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

182 Views Asked by At

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?

2

There are 2 best solutions below

0
chrisis On BEST ANSWER

You might find something like

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

a bit more flexible.

0
craigcaulfield On

You could use something like:

number(//element[1]/@value)

This navigates directly to your first element and returns the attribute value it finds.