[jdom-interest] XMLOutputter & StringWriter

Jason Hunter jhunter at collab.net
Wed Jul 5 13:02:22 PDT 2000


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

Interesting.  You'd have the encoding as an attribute of the document
itself.  I'm not sure how I feel about that.  While it seems somewhat
reasonable to specify the "character set" of a document in the document
itself (meaning which chars it can contain) it seems strange to specify
a "charset" (char-to-byte encoding) because that's more an issue for
storage/transmission.  Since for all practical purposes these two are
tied together, it'd be odd to have the document know how it'll be
encoded.

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

But what about the case where you want to output a document and all
you're given is a Writer?  Such a situation happens sometimes with
servlets, where nested includes can force you to use a Writer.  If the
outside servlet used a Writer and you call getOutputStream() it'll throw
an exception.

-jh-



More information about the jdom-interest mailing list