• Post Reply Bookmark Topic Watch Topic
  • New Topic

Is this the most efficient way to unmarshal different xml into objects based on the tags  RSS feed

 
Tony Evans
Ranch Hand
Posts: 598
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The application will be recieving xml messages that need to be unmarshalled into there respective objects. The only way to ID what the objects are is by a tag in this case I have given two examples

The first XML will contain the tag AddBookingRequest this will be unmarshalled into a bookingRequestObject.
The second XML will contain the tag SearchBookingItemRequest this will be unmarshalled into a bookingSearchRequest Object

It works, but i am interested is it the most efficient.



Thanks for any imput if there is a better wya you dont need to output all the code tell me which objects to use, i can knit the code together my self using further research.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This seems awfully clumsy - you parse into a DOM just to see if a tag exists and then go back to the input stream!



Now I don't use JAXB but surely there must be a way to take a parsed XML Element as input to an Unmarshaller.

Browsing the JavaDocs I see a method that appears to take an XML Node (as you would get from your NodeList).

Bill

 
Tony Evans
Ranch Hand
Posts: 598
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I agree it looks clumsy

The jaxb is to map straight from an xml to the object its a very neat way no fuss.

The Dom is needed since at run time the application has no idea what the xml is so looks for a key tag that will identify the xml. Now this keytag in this case SearchBookingItemRequest only contains part of the data and is not the root tag


 
chris webster
Bartender
Posts: 2407
36
Linux Oracle Postgres Database Python Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use Groovy XmlSlurper pretty easily from within Java.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!