[jdom-interest] XMLOutputter & StringWriter

Alex Chaffee guru at edamame.stinky.com
Thu Jul 6 01:25:23 PDT 2000


Elliotte says this encoding thing is a design flaw in XML.  After a
moment's reflection, it's clear he's right.  The encoding of a
document must necessarily be specifed out-of-band, i.e. in the HTTP
Header or file extension or what have you.  To prove this, what if we
had some impossible encoding where a document were encoded as a stream
of binary digits (byte 0x00 representing 0, byte 0xFF representing 1)
-- no XML parser in its right mind could even being to make sense of
that if it didn't already know what the encoding was!  Therefore by
the time it gets to the encoding="stupid" it's already too late.

So given it's a flaw, both in XML and in Writer, JDOM can't really do
anything but accept "encoding" as an opaque string.  The proper place
for this is at the moment of outputting, inside XMLOutputter; I'm
strongly against storing it in the Document (model-view distinction
again).

> 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.

Again: Not Our Problem.  We're gun manufacturers, as long as we put a
safety and a trigger lock on our product (the standard output methods
that don't take an encoding string), we're not liable for those who
turn off the safety, unlock the trigger, and shoot themselves in the
leg.


-- 
Alex Chaffee                       mailto:alex at jguru.com
jGuru - Java News and FAQs         http://www.jguru.com/alex/
Creator of Gamelan                 http://www.gamelan.com/
Founder of Purple Technology       http://www.purpletech.com/
Curator of Stinky Art Collective   http://www.stinky.com/



More information about the jdom-interest mailing list