File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Web Services and the fly likes how to handle xml as strings? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Web Services
Bookmark "how to handle xml as strings?" Watch "how to handle xml as strings?" New topic
Author

how to handle xml as strings?

Rr Kumaran
Ranch Hand

Joined: Sep 17, 2001
Posts: 548
I hava rpc encoded style web service that returns a string as response. In the string I'll storing a xml file which has CDATA sections and some inline DTD. My problem is sometimes I am getting an error from axis serialization classes saying that there is an invalid character in xml.

So is it better to convert the xml data into a BASE64 string (may be using AXIS API Or Jakarta Commons API) and return that string as response ? or is there any other way of returning xml files as strings ?

Please suggest.


RR Kumaran
SCJP 1.4
Peer Reynders
Bartender

Joined: Aug 19, 2005
Posts: 2922
    
    5
This may be of some relevance.

Processing XML with Java - Elliotte Rusty Harold
The CDATASection Interface

In essence, consider escaping (encoding) the offending characters in the text and stop using CDATA sections altogether. This of course means that you will have to decode the content on the other end.
Rr Kumaran
Ranch Hand

Joined: Sep 17, 2001
Posts: 548
Peers-

That is a nice explanation. I dont have any CDATA sections in my XML. I am wondering are there any best practices of sending xml file in SOAP messages?
Peer Reynders
Bartender

Joined: Aug 19, 2005
Posts: 2922
    
    5
Originally posted by RR Kumaran:
I dont have any CDATA sections in my XML.


Originally posted by RR Kumaran:
a xml file which has CDATA sections and some inline DTD

Data Type Definition language isn't XML. So by definition a well-formed XML document (SOAP envelope) cannot contain an inline DTD unless the inline DTD is encoded/escaped (this is why XML schema was created).
Originally posted by RR Kumaran:
I am wondering are there any best practices of sending xml file in SOAP messages?

You may be interested in
3.7 Handling XML Documents in a Web Service
If you are exchanging XML documents you may want to consider using a document-style Web service instead of an RPC-style web service.
Patterns and Strategies for Building Document-Based Web Services
[ June 27, 2006: Message edited by: Peer Reynders ]
Rr Kumaran
Ranch Hand

Joined: Sep 17, 2001
Posts: 548
Peers -

You have given me the correct answers. Thank you for all the links.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to handle xml as strings?