...">

Evaluating XPath Commands with java

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 a certificate with id 2 and I want to return it to the function. What is the best way to do this? I was thinking about XPAth Expression, how can I use them in java? What will be the best result (return value).

Thank you in advance

Sebastian

+4
source share
2 answers

Check out this article in the Java XPath API. It includes information on how to use the API, plus an example of using XPath itself.

Your XPath expression in this scenario will be

 /root/cert[@id='2'] 
+6
source

Take a look at the dom4j library. The cookbook page contains interesting code examples.

+1
source

Source: https://habr.com/ru/post/1285904/


All Articles