tags:

views:

356

answers:

2

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

A: 

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

Kees de Kooter
+5  A: 

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']
Brian Agnew