Analizando la respuesta XML del servicio RESTful en 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?

preguntado el 09 de marzo de 12 a las 22:03

do you have a schema for the xml? -

I don't think so. To be more precise about service, It's LinkedIn web service API's -

1 Respuestas

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 aquí, 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!

respondido 09 mar '12, 23:03

+1 JAXB is very easy to use. There is an unofficial schema for the LinkedIn API here: code.google.com/p/linkedin-j/source/browse/trunk/linkedin-j/…. - kevingallagher

@Andrew Thanks for link to example of working without a schema. It's very helpful. - Pregunta aleatoria

no problem. but given the size of the schema @kevingallagher linked to, you might be best using that. could save a lot of work... - Andrew Cooke

@Kevin LinkedIn has two/three different API's so ideally there would be different schema for each API. am I right? - Pregunta aleatoria

just looking at the two, it seems like the schema contains all the different replies to the REST service in one schema. for example, one of the groups api calls developer.linkedin.com/documents/groups-api devuelve un group-membership element which is present in kevin's schema here code.google.com/p/linkedin-j/source/browse/trunk/linkedin-j/… (there's also a javascript api but it looks like it returns json). good luck. - Andrew Cooke

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.