hangen
hangen

Reputation:

illegal XML characters /Axis

I've developped a web service and deployed it with Axis. All is running very well but I've a problem when I consume the service using a String containing a non printable character (such as ETX, FS,..). I have the following error:

exception: java.lang.IllegalArgumentException: The char '0x1c' after '....' is not a valid XML character.

Have you any ideas please?

edit :

I have to send a frame to my server using web service. My frame has a strict form( containing some non printable character as separator)

class Automate {void checkFrame(String frame){// checking the frame}}

wsdl file

<?xml version="1.0" encoding="UTF-8"?>

  <wsdl:part element="impl:checkFrameResponse" name="parameters"/>

  <wsdl:part element="impl:checkFrame" name="parameters"/>

  <wsdl:operation name="checkFrame">

     <wsdl:input message="impl:checkFrameRequest" name="checkFrameRequest"/>

     <wsdl:output message="impl:checkFrameResponse" name="checkFrameResponse"/>

  </wsdl:operation>

  <wsdlsoap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>

  <wsdl:operation name="checkFrame">

     <wsdlsoap:operation soapAction=""/>

     <wsdl:input name="checkFrameRequest">

        <wsdlsoap:body use="literal"/>

     </wsdl:input>

     <wsdl:output name="checkFrameResponse">

        <wsdlsoap:body use="literal"/>

     </wsdl:output>

  </wsdl:operation>

  <wsdl:port binding="impl:AutomateSoapBinding" name="Automate">

     <wsdlsoap:address location="http://localhost:8080/Gateway/services/Automate"/>

  </wsdl:port>

Upvotes: 5

Views: 10967

Answers (4)

Roi
Roi

Reputation:

use CDATA for data that is not part of the xml structure (i.e content), if i understand correctly and youre just routing messages this is what you should do.

Upvotes: 1

Jim Ferrans
Jim Ferrans

Reputation: 31012

As you form the XML you're going to tuck inside the SOAP XML envelope, you need to make sure you don't have any unescaped characters in your attribute values and in any text nodes you have in your elements. That is:

<your_elt your_attr="Don&apos;t put unescaped chars here, eg, apostrophe">
    <foo>
        Be sure to escape stuff here too, like: 2 &lt; 100
        A greek lambda is escaped like this: &#955;
    </foo>
</your_elt>

I assume you're doing this in Java, so you should look into libraries that do this for you automatically. Apache has StringEscapeUtils, for instance.

Your control characters would need to be escaped by XML numeric character references. Hopefully StringEscapeUtils handles that for you.

Hope this helps.

Upvotes: 1

Martin Peck
Martin Peck

Reputation: 11564

It sounds like you have text that can't possibly be represented in XML. You will have to escape these characters, but to be honest I suspect you should "escape" the entire string. Base64 encoding the string might work, but you could also look at MTOM or some other mechanism of passing binary data across web services.

If you own both sides of this system (the clients and the webservice) then it shouldn't be too difficult to add the encode/decode steps and base64 encoding should be enough.

Upvotes: 0

Jon Skeet
Jon Skeet

Reputation: 1500903

This is a natural problem with SOAP, unfortunately - it uses XML for text, and those characters can't be represented in XML (even with entities).

Can you escape the non-printable characters somehow? You'll need to find some way of not representing them as straight text, unfortunately.

Upvotes: 3

Related Questions