4

Hi I have an xml document like this

<root>
  <cert id="1">

  </cert>
  <cert id="2">

  </cert>
  <cert id="3">

  </cert>
</root>

now I get a request and want to select the cert with id 2 and want to return it in a function. What is the best way to do this? I thought about XPAth Expression, how can I use them in java? What would be the best output (return value).

Thanks in advance

Sebastian

2 Answers 2

6

Check out this article on the Java XPath API. It includes info on how to use the API, plus example usage of XPath itself.

Your XPath expression in this scenarion would be

/root/cert[@id='2']
Sign up to request clarification or add additional context in comments.

Comments

1

Take a look at the dom4j library. The cookbook page contains some nice code samples.

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.