aspose file tools*
The moose likes Web Services and the fly likes XML Escape Newline Characters Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Web Services
Bookmark "XML Escape Newline Characters " Watch "XML Escape Newline Characters " New topic
Author

XML Escape Newline Characters

Alex Lee
Greenhorn

Joined: May 05, 2004
Posts: 5
Hi all,

I have big problem URGENTLY when i try to send a SOAP request which include newline character to web service

If i substitue newline character with
the soap request in xml will look like this 
 (auto escaping for me)

If i substitue newline character with 

the soap request in xml will look like this 
 (auto escaping for me)

If i substitue newline character with ![CDATA[ ]]
the soap request in xml will look like this ![CDATA[ ]] BUT the web service server will take the value as it is ![CDATA[ ]]
I want to make sure the web service server interpret ti as \n
I need to explicitly specifiy this value in the soap request xml, so that the web service server process it as \n

How do i manage to do that?
Zillions thanks if anyone can help

Ivan Krizsan
Ranch Hand

Joined: Oct 04, 2006
Posts: 2198
    
    1
Hi!
Would encoding the string data containing the newline character(s) using base-64 be an option for you?
This would of course mean that the client must encode the string and that the string later must be decoded on the server side.
Best wishes!


My free books and tutorials: http://www.slideshare.net/krizsan
Alex Lee
Greenhorn

Joined: May 05, 2004
Posts: 5
Hi
If i were to use data encoding Base64, then server side must change too, am i right?

In short, i just want to make sure in my SOAP request
i can have this value only 
 NOT 


Because only this value, the server side can interpret as newline

Thanks for all help.....
H Paul
Ranch Hand

Joined: Jul 26, 2011
Posts: 381
Software engineering or Software plumbing: The issue is Predefined entities in XML.

I don't know how on the client side, the soap request message is generated.
But can you just POST it as an "xml String" using java.net.URL or Apache client.

For example:


But even if it's OK for the client to successfully sent to the server 

I'm not sure how the server soap engine see it. I doubt it will preserve 

It will re-inprete/translate as 

Then it will forward that to the target endpoint which will see it as 
 (which is unwanted)

If possible, what/how is your client and server is using?

EDITED: to display the values: 
 

Alex Lee
Greenhorn

Joined: May 05, 2004
Posts: 5
Hi,

We are not sure what the server engine using. It is external party integration

We have tested by putting the value &#10 directly in the server side, the server know how to interpret it as \n (newline)

So now we want to make sure our client generated the SOAP request with value 
 NOT 


For client, we are using Axis.

So we don't take care of the URL.post (getSOAPRequestMessage)
We auto generated the client using Axis WSDL2Java, so we have classes like
WebService_ServiceLocator, WebServicePortBindingStub,WebService_PortType and etc




ARRGH , i wanna cry already... is that limitation of SOAP???

PLEASE HELP ANYONE


H Paul wrote: Software engineering or Software plumbing: The issue is Predefined entities in XML.

I don't know how on the client side, the soap request message is generated.
But can you just POST it as an "xml String" using java.net.URL or Apache client.

For example:


But even if it's OK for the client to successfully sent to the server 

I'm not sure how the server soap engine see it. I doubt it will preserve 

It will re-inprete/translate as 

Then it will forward that to the target endpoint which will see it as 
 (which is unwanted)

If possible, what/how is your client and server is using?

EDITED: to display the values: 
 

H Paul
Ranch Hand

Joined: Jul 26, 2011
Posts: 381
A. Possible options with the Soapful-based web service:

1. Construct the xml String and POST it using URL for example as the code sample shown.
The question is how big the SOAP message look like?

2. Construct the SOAP Message using SAAJ api and send the SOAP message using SAAJ.

3. Using WSDL2Java as you did BUT now you to find a way to let override
the underlying "Character Escaping Control of XML entities" of the SOAP engine, in your case AXIS
i.e look into AXIS api to look where you can do that,
i.e tell it NOT to convert the 
 to 


For option 3: even if you use another SOAP engine/toolkit/stack, you still have to
override the underlying "Character Escaping Control of XML entities"

4. Some one else see some thing else that I do not see.

B. Possible options with the Restful-based web service:

1. Ask if your third-party provide a Restful webservice where you can use JAX-RS client api
will make your life easier instead of A.1, A.2, A.3.

EDITED: to display the values: 
 

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: XML Escape Newline Characters
 
Similar Threads
How to read \n in XML
filtering illegal characters in xml documents
How to display "\n" in xml file?
Am I just stupid, or is this really supposed to be difficult?
SOAP Fault for SOAP Action property