[jdom-interest] Dealing with binary characters in-memory -> outputter

Attila Szegedi szegedia at freemail.hu
Fri Sep 21 06:33:41 PDT 2001


Strange. I've never came across a situation where XMLOutputter "ignores"
UTF-8. It may be optimized in a way that it does not output encoding
specification into the output XML declaration. It is completely legal, as
the default encoding per XML spec is UTF-8, so it can be omitted in this
case.

If this is not the issue, then it might be that you're not specifying UTF-8
everywhere you should. I hope you're aware that in order to have
XMLOutputter use specific encoding, you must specify the encoding BOTH to a
Writer AND to the XMLOutputter setEncoding, like:

File outputFile = ...;
String encoding = "UTF-8";
Document doc = ....;

Writer w = new BufferedWriter(new OutputStreamWriter(new
FileOutputStream(outputFile), encoding));
try
{
    XMLOutputter outputter = new XMLOutputter();
    outputter.setEncoding(encoding);
    outputter.output(doc, w);
}
finally
{
    w.close();
}

Attila.

----- Original Message -----
From: "Mark Bennett" <mbennett at ideaeng.com>
To: "Attila Szegedi" <szegedia at freemail.hu>; <jdom-interest at jdom.org>
Sent: 2001. szeptember 21. 11:14
Subject: RE: [jdom-interest] Dealing with binary characters in-memory ->
outputter


> Hello Attila,
>
> Thanks for your suggestion.
>
> I had tried UTF-8, but the outputter seemed to ignore it.
> I agree, if authoring XML in an ASCII editor, that would
> be a fine way to do it.
>
> And I hear what you're saying about the different encodings
> having different characters.
>
> But how about for a given encoder:
> * Is this character in my map?
> Yes
> then output it as it is mapped
> No
> then use the generic escape sequence &#xNN;
>
> So instead of tracking rules for every character, it would
> simply need to know that this wasn't in it's map, so it should
> therefore use the generic escaping.
>
> I think...
>

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 2848 bytes
Desc: not available
Url : http://jdom.org/pipermail/jdom-interest/attachments/20010921/b482b552/smime.bin


More information about the jdom-interest mailing list