RandomQuestion
RandomQuestion

Reputation: 6998

Parsing XML response from RESTful service in java

Please bear with me for this novice question.

I am calling a RESTful web service APIs that returns XML response. Apart from normal XML parsing schemes like DOM based parsing, SAX based parsing, is there a way to transform this XML response directly into some object? What more details/specification from service side would be required to do such transformation?

Upvotes: 2

Views: 12296

Answers (1)

andrew cooke
andrew cooke

Reputation: 46892

i can't give a summary of all the options available, but i recently used jaxb to do the opposite (java to xml) and it was simple and easy to use. since jaxb also supports xml to java, as described here, i would suggest giving that a look. it's based on annotations and java beans (or pojos) - you just indicate which attributes correspond to the elements with attributions, and it does the rest.

if you have a schema, it will generate java classes for you. alternatively, here's an example of working without a schema.

ps according to comments in the final link, you don't even need to annotate if the names match the xml!

Upvotes: 3

Related Questions