You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by Tony Field <to...@fatwire.com> on 2004/04/13 22:32:52 UTC

invalid character question

Hello,
This is my first post to this list, so I apologize if this issue has 
been addressed.
I'm using Axis as a client to a web service. The client stubs were 
generated using wsdl2java. Everything seems to work well for me, except 
when my XML document body contains the 1C character. To get around 
this, our web service encloses our document data in a cdata block. When 
we encounter a character that is not valid (per 
http://www.w3.org/TR/2004/REC-xml-20040204/#charsets), we close the 
cdata block and escape the character using &#refNo; for each invalid 
character, then re-open the cdata block and continue with the document.
So, for example a document may look like this:
  <item><![CDATA[The words ]]>&#28;<![CDATA[what is in your 
wallet]]></item>
The problem I'm having is that the axis client is throwing an exception 
parsing the response with this data in it. The exception thrown is 
listed below. Why is axis failing to parse this response? I see the 
failure using both xerces and crimson. A colleague has tested this 
using XMLSpy and it does not fail to parse the response - the response 
looks exactly like what I show above.
Any help would be greatly appreciated.
Sincerely,
Tony

Re: invalid character question

Posted by Dennis Sosnoski <dm...@sosnoski.com>.
Steve Loughran wrote:

>Tony Field wrote:
>
>  
>
>>...Everything seems to work well for me, except 
>>when my XML document body contains the 1C character. To get around this, 
>>our web service encloses our document data in a cdata block. When we 
>>encounter a character that is not valid (per 
>>http://www.w3.org/TR/2004/REC-xml-20040204/#charsets), we close the 
>>cdata block and escape the character using &#refNo; for each invalid 
>>character, then re-open the cdata block and continue with the document.
>>So, for example a document may look like this:
>>
>><item><![CDATA[The words ]]>&#28;<![CDATA[what is in your wallet]]></item>
>>The problem I'm having is that the axis client is throwing an exception 
>>parsing the response with this data in it. The exception thrown is 
>>listed below. 
>>    
>>
>
>...
>
>I assume you are running Axis1.2beta? This contains reworked charset 
>stuff. If we still have a problem in there, then we have a problem.
>
>I do know that Axis1.2 is strict about what is legal XML. I dont know if 
>it correctly decodes &#xxx when xxx<32 & != tab, cr, or lf. Indeed, I 
>dont know what the correct behaviour should be.
>  
>
The error message is absolutely correct. The only characters < 0x20 that 
are valid in an XML 1.0 document are tab, cr, and lf. Using a character 
reference doesn't change this - see the XML 1.0 recommendation, "4.1 
Character and Entity References":

"Well-formedness constraint: Legal Character

Characters referred to using character references must match the 
production for Char."

where "Char" is the rule that says that the only valid characters < 0x20 
are tab, cr, and lf. The only purpose of character references in XML 1.0 
is to avoid the limitations of character encodings such as ASCII that 
can't represent the full range of Unicode characters directly.

If you need to represent character codes in this range in your data, 
your only alternatives using XML 1.0 are to define your own substitution 
character (which your processing will then replace by the invalid 
character, after it's been through the XML layer) or use base64binary 
(basically a byte[], in Axis terms).

Just to confuse the issue, XML 1.1 actually changes this so that you 
*can* use characters < 0x20, != 0, with references. No tools that I know 
of support XML 1.1 yet, though.

  - Dennis

-- 
Dennis M. Sosnoski
Enterprise Java, XML, and Web Services
Training and Consulting
http://www.sosnoski.com
Redmond, WA  425.885.7197



Re: invalid character question

Posted by Steve Loughran <st...@iseran.com>.
Tony Field wrote:

> Hello,
> This is my first post to this list, so I apologize if this issue has 
> been addressed.
> I'm using Axis as a client to a web service. The client stubs were 
> generated using wsdl2java. Everything seems to work well for me, except 
> when my XML document body contains the 1C character. To get around this, 
> our web service encloses our document data in a cdata block. When we 
> encounter a character that is not valid (per 
> http://www.w3.org/TR/2004/REC-xml-20040204/#charsets), we close the 
> cdata block and escape the character using &#refNo; for each invalid 
> character, then re-open the cdata block and continue with the document.
> So, for example a document may look like this:
> 
> <item><![CDATA[The words ]]>&#28;<![CDATA[what is in your wallet]]></item>
> The problem I'm having is that the axis client is throwing an exception 
> parsing the response with this data in it. The exception thrown is 
> listed below. 

I didnt see it; can you repost?

>Why is axis failing to parse this response? I see the 
> failure using both xerces and crimson. A colleague has tested this using 
> XMLSpy and it does not fail to parse the response - the response looks 
> exactly like what I show above.
> Any help would be greatly appreciated.
> Sincerely,
> Tony
> 

I assume you are running Axis1.2beta? This contains reworked charset 
stuff. If we still have a problem in there, then we have a problem.

I do know that Axis1.2 is strict about what is legal XML. I dont know if 
it correctly decodes &#xxx when xxx<32 & != tab, cr, or lf. Indeed, I 
dont know what the correct behaviour should be.

Re: invalid character question

Posted by Tony Field <to...@fatwire.com>.
Thank you Gary, that explains my question exactly.  I did not 
understand that you couldn't even have a reference to an invalid 
character in a well-formed xml document.

Tony

On 14-Apr-04, at 3:30 AM, Gary L Peskin wrote:

> As indicated in your cited reference to the XML 1.0 Recommendation, 
> the character $#28 is -not- a valid XML 1.0 character (ie Char) and 
> cannot appear in a well-formed XML document.  This is true regardless 
> of whether the character appears directly or through a character 
> reference.  Whether it appears inside or outside of a CDATA section is 
> of no consequence whatsoever.  The CDATA section is provided to 
> include < and & without the need to escape them (which is required in 
> a non-CDATA section). 
>   
> HTH,
> Gary
> -----Original Message-----
> From: Tony Field [mailto:tony.field@fatwire.com]
>  Sent: Tuesday, April 13, 2004 1:33 PM
> To: axis-dev@ws.apache.org
> Subject: invalid character question
>
> Hello,
> This is my first post to this list, so I apologize if this issue has 
> been addressed.
> I'm using Axis as a client to a web service. The client stubs were 
> generated using wsdl2java. Everything seems to work well for me, 
> except when my XML document body contains the 1C character. To get 
> around this, our web service encloses our document data in a cdata 
> block. When we encounter a character that is not valid (per 
> http://www.w3.org/TR/2004/REC-xml-20040204/#charsets), we close the 
> cdata block and escape the character using &#refNo; for each invalid 
> character, then re-open the cdata block and continue with the 
> document.
> So, for example a document may look like this:
>
> <item><![CDATA[The words ]]>&#28;<![CDATA[what is in your 
> wallet]]></item>
> The problem I'm having is that the axis client is throwing an 
> exception parsing the response with this data in it. The exception 
> thrown is listed below. Why is axis failing to parse this response? I 
> see the failure using both xerces and crimson. A colleague has tested 
> this using XMLSpy and it does not fail to parse the response - the 
> response looks exactly like what I show above.
> Any help would be greatly appreciated.
> Sincerely,
> Tony


RE: invalid character question

Posted by Gary L Peskin <ga...@firstech.com>.
As indicated in your cited reference to the XML 1.0 Recommendation, the
character $#28 is -not- a valid XML 1.0 character (ie Char) and cannot
appear in a well-formed XML document.  This is true regardless of whether
the character appears directly or through a character reference.  Whether it
appears inside or outside of a CDATA section is of no consequence
whatsoever.  The CDATA section is provided to include < and & without the
need to escape them (which is required in a non-CDATA section).  
 
HTH,
Gary

-----Original Message-----
From: Tony Field [mailto:tony.field@fatwire.com] 
Sent: Tuesday, April 13, 2004 1:33 PM
To: axis-dev@ws.apache.org
Subject: invalid character question


Hello,
This is my first post to this list, so I apologize if this issue has been
addressed.
I'm using Axis as a client to a web service. The client stubs were generated
using wsdl2java. Everything seems to work well for me, except when my XML
document body contains the 1C character. To get around this, our web service
encloses our document data in a cdata block. When we encounter a character
that is not valid (per
http://www.w3.org/TR/2004/REC-xml-20040204/#charsets), we close the cdata
block and escape the character using &#refNo; for each invalid character,
then re-open the cdata block and continue with the document.
So, for example a document may look like this:

<item><![CDATA[The words ]]>&#28;<![CDATA[what is in your wallet]]></item>
The problem I'm having is that the axis client is throwing an exception
parsing the response with this data in it. The exception thrown is listed
below. Why is axis failing to parse this response? I see the failure using
both xerces and crimson. A colleague has tested this using XMLSpy and it
does not fail to parse the response - the response looks exactly like what I
show above.
Any help would be greatly appreciated.
Sincerely,
Tony