[jdom-interest] XMLOutputter & StringWriter

Elliotte Rusty Harold elharo at metalab.unc.edu
Wed Jul 5 05:23:14 PDT 2000

>> On Mon, Jul 3, 2000 19:07 Uhr, Jason Hunter <mailto:jhunter at collab.net>
>> wrote:
>> >  I propose we don't provide
>> >
>> >output(Document, Writer)
>> >
>> >and only provide
>> >
>> >output(Document, Writer, String encodingOfWriter)
>> >

You can't change the encoding of an existing writer using the 
standard java.io classes. It can be done with your own custom 
classes, barely, but it's too ugly for me to feel comfortable with.

More importantly, this proposed method signature potentially passes 
the same information, the encoding name, in all three arguments, 
which may not always agree with each other. The problem is the writer 
may have a different encoding than the one we pass in. e.g. the 
writer could be writing 8859-1 but the encoding could say SJIS. 
Furthermore, what if the document specifies a different encoding 
entirely through its encoding declaration? We could potentially be 
specifying three different encodings here.

JDOM right now doesn't provide the encoding declaration, either for 
writing or reading; but I suspect eventually it will and that that is 
the right way to specify the output encoding.

What's really going on here is that XML doesn't work well with 
out-of-band means of determining encodings like OutputStreamWriters 
and HTTP Content-type headers. This is a known problem with XML that 
has caused some argument in the XML working groups at the W3C. I 
don't think we can fix that issue here, or even comfortably work 
around it. I propose we just stick to the pure OutputStream 
signatures and build any writers we use internally with the encoding 
as specified in the encoding declaration. The API to this could be a 
simple setEncoding() method in the Document class. We should never 
provide any means other than the encoding declaration to specify the 

| Elliotte Rusty Harold | elharo at metalab.unc.edu | Writer/Programmer |
|                  The XML Bible (IDG Books, 1999)                   |
|              http://metalab.unc.edu/xml/books/bible/               |
|   http://www.amazon.com/exec/obidos/ISBN=0764532367/cafeaulaitA/   |
|  Read Cafe au Lait for Java News:  http://metalab.unc.edu/javafaq/ |
|  Read Cafe con Leche for XML News: http://metalab.unc.edu/xml/     |

More information about the jdom-interest mailing list