[jdom-interest] XMLOutputter & StringWriter

Jason Hunter jhunter at collab.net
Tue Jul 4 12:21:11 PDT 2000


Alex Chaffee wrote:
> 
> Sorry, I didn't read your reply before making mine.
> 
> Sounds like we need to be able to say writer.getEncoding(), as in
> 
>  "<?xml version=\"1.0\" encoding=\"" + writer.getEncoding() + "\" ?>"
> 
> but unfortunately, that method is only defined on OutputStreamWriter.
> Therefore Jason is right, and we need to "cheat" and pass the desired
> encoding in directly to the XMLOutputter.
> 
> I think. :-)

Exactly, we need to put the encoding in the declaration, and we can't
get the encoding from the Writer, so we have to get it from the user.

Writing to a StringWriter is an odd case because you're not really
encoding it and so the encoding in the decl doesn't make a whole lot of
sense, but at the end of the day when you take that String and output it
to bytes it'll be in some encoding, and the document itself has to
report what encoding that is.  That's another reason why JDOM is a
better in-memory representation of an XML document than a String.  :-)

-jh-



More information about the jdom-interest mailing list