0

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.

3
  • 1
    But its always throwing exception. - Adding the exception to your question would be a big help. Commented May 23, 2016 at 14:55
  • 1
    @Loic M. Do change user-provided code or markup unless you are certain you're properly representing OP's intent without affecting the issue at hand; in this case you cannot be and should not have made such changes. Rolled back. Commented May 23, 2016 at 14:56
  • @DanielHaley..The exception thrown is exceptionjavax.xml.transform.TransformerException: A location step was expected following the '/' or '//' token. Commented May 24, 2016 at 8:41

3 Answers 3

2

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]
Sign up to request clarification or add additional context in comments.

2 Comments

For //dsml/entries/entry/att[@name='uid']/value[1], I am getting "NullException"
I have tested here: freeformatter.com/xpath-tester.html It works fine there.
0

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] 

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.