-2

I have consumed rest Webservice and I get a response in text format, I want to convert this response to java object in order to do some logic.

I have tried to parse the text to XML unfortunately, doesn't work.

Response from web service:

<html>
<title>rest response</title>
<body>
<a href="http://Xwebservice-urlXXX/XY111NWA1">XY111NWA1</a>
<a href="http://Xwebservice-urlXXX/XY112NWA1">XY112NWA1</a>
<a href="http://Xwebservice-urlXXX/XY113NWA1">XY113NWA1</a>
<a href="http://Xwebservice-urlXXX/XY114NWA1">XY114NWA1</a>
<a href="http://Xwebservice-urlXXX/XY115NWA1">XY115NWA1</a>
<a href="http://Xwebservice-urlXXX/XY116NWA1">XY116NWA1</a>
<a href="http://Xwebservice-urlXXX/XY117NWA1">XY117NWA1</a>
<a href="http://Xwebservice-urlXXX/XY118NWA1">XY118NWA1</a>
<a href="http://Xwebservice-urlXXX/XY119NWA1">XY119NWA1</a>
</body>
</html>

I expect the output to be in XML format so I can parse then to JAVA object, or get the date between tags and the result should be a java list as follows:

XY111NWA1
XY112NWA1
XY113NWA1
XY114NWA1
XY115NWA1
XY116NWA1
XY117NWA1
XY118NWA1
XY119NWA1
Oussama EL ABED
  • 129
  • 1
  • 1
  • 10

1 Answers1

1

That's not a REST response(not a JSON or response formatted XML), so if you need to parse HTML page(or html-like response).

WAY 1: I would rather recommend such tool as a jsoup:

This way you can extract any node/value/attribute from your html response/file.

WAY 2 You can try more general SAX or JAXB parsers for parsing xml (even if it's HTML) like in https://www.mkyong.com/java/jaxb-hello-world-example/ . But that's if you have some contract in your response. And from what I see that's not a best approach here.

Relevant link: Which is the best library for XML parsing in java

Mykola Korol
  • 638
  • 6
  • 10