• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to return XML data as a string?  RSS feed

 
Alan Davey
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I'm a newbie to web services and I'm having difficulty returning an "xml formatted" string from a simple java class. All of the "less-than" and "greater-than" symbols get converted to:
"& lt;" and "& gt;" without the spaces
respectively.

I'm currently using JDeveloper and having it create the WSDL based on my java class. The return type in WSDL is a simple "xsd:string" as I would expect.

Because of this change from my literal character of '<' and '>' to the expanded xml notation, I am having problems consuming the response in client applications. BTW, what is the proper terminology for this character translation of reserved xml characters?

I just did another test where if I define my WSDL using the xsd schema of my expected result set and then have JDeveloper generate the java classes, my webservice will return xml in the proper format that I expected.

However, this seems like overkill as it could generate tons of java classes for complex xml schemas, which in turn makes it more difficult to populate with my xml data. Is this the correct approach (best practice) that I should be taking?

My ultimate goal is to produce an xml result set from my database (easy), have a java class get this result set and return it as a string (easy) and have the SOAP response preserve my return string verbatim (hard). Should I be looking into a REST solution instead of a SOAP solution? In my early testing, when I invoked my web service via REST, it did preserve my return string verbatim.

Thanks,

Alan

[ August 21, 2007: Message edited by: Alan Davey ]

[ August 21, 2007: Message edited by: Alan Davey ]
[ August 21, 2007: Message edited by: Alan Davey ]
 
Peer Reynders
Bartender
Posts: 2968
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Some of the information in this topic may help.
 
Alan Davey
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the link.

I was able to get this working by setting the return type of my method to Document (org.w3c.dom.Document).

In the body of my method, the relevant code I added was:


In the code above xmlResult was the "xml" string that I had previously built.

Next steps will be to create a proper schema file for validation and for use in the types definition of the WSDL.

Alan
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!