Shashank Lahariya
Shashank Lahariya

Reputation: 109

Using xpath,how to fetch particular xml node value when node contains multiple value?

Here is the xml from which i want to retrieve the value.

<dsml>
<entries>
<entry dn="uid=7686,c=in,ou=pages,o=example.com">
<att name="uid">
<value>7568766</value>
<value>756876634</value>
</att><att name="callname">
<value>jhsadkjh</value>
<value>jhsadkjhakjdgakj</value>
</att></entry>
</entries>
</dsml>

As you can see that each attribute is having 2 values associated with it. I want to fetch only first one. Below are some xpaths i have used:

//dsml/entries/entry/att[@name = 'uid']/value[1]
//dsml/entries/entry/att[@name = 'uid']/value/[1]

But its always throwing exception.

Upvotes: 0

Views: 183

Answers (3)

Sergey  Nazarenko
Sergey Nazarenko

Reputation: 159

This xpath fetch only second 'value' tag from each tag named 'att':

//dsml/entries/entry/att/value[1]

or, if you want to fetch 'value' only from "uid", you can use:

//dsml/entries/entry/att[@name='uid']/value[1]

Upvotes: 2

You are using different names for the same element. entries as open tag and enteries as closing tag. These names should be identical. Also in xml the name of element is att and in Xpath you are trying to find attr

Upvotes: 0

choroba
choroba

Reputation: 241738

att and attr aren't the same element. Also, </enteries> can't close <entries>.

The following worked for me in xsh:

/dsml/entries/entry/att[@name = 'uid']/value[1] 

Upvotes: 0

Related Questions