[jdom-interest] XMLOutputter & StringWriter

Jason Hunter jhunter at collab.net
Mon Jul 3 10:38:18 PDT 2000


> In my understanding all Writers are (unicode) character streams. This way
> you get rid of the encoding problem, that only arises when going to _byte_
> streams and vica versa. So you only need the encoding parameter for the
> character <--> byte stream transition.
> Since the proposed method does not involve byte streams, and all info in a
> Document is represented(able) as characters, encoding is not necessary.
> 
> My knowledge comes from
> 
> http://java.sun.com/products/jdk/1.2/docs/guide/io/io.html

What's wrong with the following?

res.setContentType("text/html");
XMLOutputter outputter = new XMLOutputter();
outputter.output(doc, res.getWriter())

What's wrong is that the Writer is Latin-1 so that's what the document
chars will be encoded in, but in the document's declaration we'll write
that it's encoded in UTF-8 because that's our default.  Any reader will
get confused trying to read Latin-1 as UTF-8.

-jh-



More information about the jdom-interest mailing list