Fetching an Xml Listobject depending on the value in one of its keys

17 Views Asked by At

I am currently going through an xml data,

<datas>
    <data>
        <key1>ABC</key1>
        <key2>def</key2>
    </data>
    <data>
        <key1>PQR</key1>
        <key2>xyz</key2>
    </data>
</datas>

Here i want to fetch the value in tag key2 from the data where the key1 is PQR

I had used the xpath expression

//datas/data[last()]/key2

but this one will work only if the last data is having the value.

what will be the xpath expression to fetch the same?

1

There are 1 best solutions below

0
miriamka On

Here it is:

/datas/data[key1="PQR"]/key2