You are viewing a plain text version of this content. The canonical link for it is here.
Posted to xmlrpc-dev@ws.apache.org by String Larson <st...@mac.com> on 2005/05/24 20:16:18 UTC

Invalid character data...

I'm getting:
XmlRpcClientException: Invalid Character data corresponding to XML 
entity &#65533

The cause is a copyright char &#169; in a String.

This works fine on Win32 and OSX but throws exceptions on Linux.

I'm able to parse an XML file containing the string just fine:

eg:

<line1>Copyright &#169; 2005 Foo</line>

Any ideas ?


Re: Invalid character data...

Posted by String Larson <st...@mac.com>.
Thanks.
The problem is the default character encoding (System prop 
file.encoding) on Linux was UTF8 and on WIn32 was cp1252.  As I'm using 
org.apache.commons.configuration.XMLConfiguration to read a config 
file. From which,  the &#169; was not properly recognized on Linux.
Using -Dfile.encoding = cp1252 when launching JBoss solves the problem.

Thanks for the heads up on StringWriter. I use ByteArrayOutputStream so 
often for things, that take OutputStream that its just habit.

I'll look into the b20050512_streaming branch.

Thanks.

On May 26, 2005, at 6:54 AM, Jochen Wiedmann wrote:

> String Larson wrote:
>
>>   return baos.toString();
>
> What character encoding does the machine have? Is ISO-8859-1 the 
> default
> locale? Otherwise, you would most possibly need a 
> toString("ISO-8859-1")
> here.
>
> Besides, does the generated string contain an XML declaration with
> encoding='ISO-8859-1'?
>
> If not, try to create a small example program, which demonstrates the
> problem. Besides, is there any reason for using a ByteArrayOutputStream
> as the transformer target? As you are going to create a string anyways,
> that's an unnecessary performance loss, compared to a StringWriter.
>
> And, finally, if you are transferring DOM documents, you might take a
> look at the b20050512_streaming branch, which supports DOM nodes as
> request parameters and results.
>
> Jochen


Re: Invalid character data...

Posted by Jochen Wiedmann <jo...@gmail.com>.
String Larson wrote:

>   return baos.toString();

What character encoding does the machine have? Is ISO-8859-1 the default
locale? Otherwise, you would most possibly need a toString("ISO-8859-1")
here.

Besides, does the generated string contain an XML declaration with
encoding='ISO-8859-1'?

If not, try to create a small example program, which demonstrates the
problem. Besides, is there any reason for using a ByteArrayOutputStream
as the transformer target? As you are going to create a string anyways,
that's an unnecessary performance loss, compared to a StringWriter.

And, finally, if you are transferring DOM documents, you might take a
look at the b20050512_streaming branch, which supports DOM nodes as
request parameters and results.

Jochen

Re: Invalid character data...

Posted by String Larson <st...@mac.com>.
On May 25, 2005, at 3:32 PM, Jochen Wiedmann wrote:

> String Larson wrote:
>
>> <line1>Copyright &#169; 2005 Foo</line>
>
> That line is okay, as it is. However, the question is, whether it looks
> the same internally. You provide too less information for a guess. For
> example, it is unclear, what you are parsing: An input stream, a 
> reader,
> a file, whatever. If it is an input stream: What is the character
> encoding, and all the like.


Here is a fragment of the XML string I am passing as a parameter to the 
RPC call

<template clientId="1">
	<borderElement>
		<copyright line1="Copyright &amp;#169; 2005" line2="Images provided 
by someone."/>
	</borderElement>
</template>

This String was encoded using the following:

public String toXMLString() {
   	TransformerFactory tranFactory = TransformerFactory.newInstance();
   	Transformer aTransformer = null;
   try {
    	aTransformer = tranFactory.newTransformer();
   } catch (TransformerConfigurationException e) {
   	 e.printStackTrace();
   }

   Source src = new DOMSource(getDoc());
   ByteArrayOutputStream baos = new ByteArrayOutputStream();
   Result dest = new StreamResult(baos);
   try {
     	aTransformer.setOutputProperty(OutputKeys.ENCODING, "iso-8859-1");
    	aTransformer.transform(src, dest);
   } catch (TransformerException e1) {
   	 e1.printStackTrace();
   }
   return baos.toString();
  }

The String is added as a parameter to an XmlRpcClient.execute() call.
eg.
Vector params = new Vector();
params.add(ptd.toXMLString());
XmlRpcClient c = new XmlRpcClient();
c.execute("http://...", params);


This works fine in Win32 land, and is picked up fine by my XMLRPC 
server running on OSX 10.3.9.
However, when the client is running on Linux, I get the invalid 
character data exception.

Thanks.




Re: Invalid character data...

Posted by Jochen Wiedmann <jo...@gmail.com>.
String Larson wrote:

> <line1>Copyright &#169; 2005 Foo</line>

That line is okay, as it is. However, the question is, whether it looks
the same internally. You provide too less information for a guess. For
example, it is unclear, what you are parsing: An input stream, a reader,
a file, whatever. If it is an input stream: What is the character
encoding, and all the like.


Jochen