[jdom-interest] XMLOutputter & StringWriter

Elliotte Rusty Harold elharo at metalab.unc.edu
Thu Jul 6 04:11:15 PDT 2000

At 6:55 PM -0700 7/5/00, Jason Hunter wrote:

>You're assuming you don't know what encoding the writer uses.  Most
>often you do know.  You do in the servlets case at least; the API is
>just trying to play it safe and ensure once you start writing chars you
>don't try to sneak out bytes.  If we provide an output(Document, Writer,
>String) and the String is defined as the encoding used to construct the
>writer (or perhaps just the encoding to write in the declaration), then
>if you don't know the encoding of your writer it's pretty clear to you
>that you're stuck.  :-)

Once we provide this method though, there's no way to restrict it 
just to servlets. It will be public for anyone who wants to use it, 
correctly or incorrectly. The fact is more developers don't 
understand encodings than do, as the large number of Cp1252 Web pages 
mislabeled as Latin-1 proves. I'm just not willing to trust 
developers to do the right thing here if we make it easy for them to 
do the wrong thing.

Is there anyway we could reverse the problem? Would it be enough if 
getSerializedForm() worked, either directly in Document or from 
XMLOutputter as Brett suggested, so that a servlet could simply write 
the serialized form? Though I suppose that really just sweeps the 
problem under the rug, since a Unicode string form of a document 
might get written onto a non-Unicode writer without changing the 
encoding declaration to match. In that case, however, it's no longer 
JDOM doing the wrong thing.

I don't yet see a way out of this conundrum. Again we're butting our 
heads up against what is perhaps bad design in XML itself.

| 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