Rishi
Rishi

Reputation: 1

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

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?

Upvotes: 0

Views: 16

Answers (1)

miriamka
miriamka

Reputation: 481

Here it is:

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

Upvotes: 1

Related Questions