tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michael Mealling <>
Subject serializing XML to a ServletOutputStream fails
Date Mon, 05 Feb 2001 02:04:10 GMT
(This might be a bug so I'm cc-ing to tomcat-dev)
    I'm trying to serialize some XML out to a ServletOutputStream but
the resulting XML on the client side contains corrupted Unicode
characters (the DOM I'm serializing out contains Chinese, Korean,
English, etc). Here's the code in question:

        response.setContentType("text/xml; charset=UTF-8");
        ServletOutputStream out = response.getOutputStream();

        out.print("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
                   "<!DOCTYPE cnrp PUBLIC \"-//IETF//DTD CNRP 1.0//EN\"" +
                   " \"\">\n");
        OutputFormat format = new OutputFormat(document);
        format.setIndenting(true); // it makes debuggin easier
        format.setEncoding("UTF-8"); // this is the default anyway
        XMLSerializer serializer = new XMLSerializer(out, format);

The XML that the client gets is fine except that the non-ASCII subset
of the UTF-8 encoded Unicode characters are garbled. I can serialize
the XML out to a FileOutputStream and it works just fine.

I'm running Tomcat 3.2.1 that's the backend for a remote
Apache 1.3.17 server using ajp13 (and thus mod_jk).

This code looks like its the right way to do this but either
I've hit a bug or else I'm missing something (an encoding somewhere
between a Stream and a Writer?)


Michael Mealling	|      Vote Libertarian!       |
Sr. Research Engineer   |     | ICQ#:         14198821
Network Solutions	|          |

View raw message