Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Better way to return XML document

 
forums UseR
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello

How to go about converting a ResultSet into XML document, which I have to return as output from a Web Service.

I tested the Web Service by returning a String form of ResultSet, which looks like a huge ugly blob...

Any slick ideas please...

Thanks

Srinivas


 
Ivan Krizsan
Ranch Hand
Posts: 2198
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!
Have you considered the following:
- For each row from the database, create and populate a JAXB bean class instance.
- Marshal the JAXB bean class instances to XML.
Best wishes!
 
forums UseR
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply!

How should I return the final XML from the web service though?
 
Ivan Krizsan
Ranch Hand
Posts: 2198
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!
If you want to use the JAX-WS way, then you do not have to return the XML, but you can return, for instance, a JAXBSource object.
For an example on how to do that, see page 157 in this document: http://faq.javaranch.com/content/Exam-Objectives-5.pdf
Best wishes!
 
Vinod K Singh
Ranch Hand
Posts: 198
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
srinivas chary wrote:How should I return the final XML from the web service though?

XML is also just an String data type, so web service method needs to return the String (XML). It works pretty well, see here Send XML data over web service.
 
forums UseR
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does anybody have ideas, on developing a web service that returns a XML file (converted from a result set, using JAXB)...


 
Deepak Bala
Bartender
Posts: 6663
5
Firefox Browser Linux MyEclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Open the PDF given by Ivan and search for JAXBSource
 
forums UseR
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I searched on javaranch.com. And I came across this framework "XStream" which is quite easy to use. Boils down to couple lines of code...explained in this blog

Thanks for all your replies...

Srinivas


 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic