New serializeDocument(Elem, OutputStream) to be used with OutputStreams. #56

Merged
merged 1 commit into from Sep 25, 2011

Projects

None yet

2 participants

@hvesalai

Uses the character encoding of the XMLSerializer.

Motivation: when XMLSerializer is created, an encoding is specified. This
encoding is used when writing the XML declaration. Using the
serializeDocument(Elem, Writer) can lead to a stupid-user-error where the
encoding given and the encoding of the Writer (e.g. OutputStreamWriter) are not
the same.

For example, on a platform, whose default encoding is ISO-8859-1, the following
innocent looking code would lead to a disaster:

XMLSerializer("UTF-8", true).serializeDocument(root, new OutputStreamWriter(myOutputStream))

In the above, the declaration written by XMLSerializer would state "UTF-8", but
the data written by the Writer would be in ISO-8859-1.

Heikki Vesalainen New serializeDocument(Elem, OutputStream) to be used with OutputStreams.
Uses the character encoding of the XMLSerializer.

Motivation: when XMLSerializer is created, an encoding is specified. This
encoding is used when writing the XML declaration. Using the
serializeDocument(Elem, Writer) can lead to a stupid-user-error where the
encoding given and the encoding of the Writer (e.g. OutputStreamWriter) are not
the same.

For example, on a platform, whose default encoding is ISO-8859-1, the following
innocent looking code would lead to a disaster:

XMLSerializer("UTF-8", true).serializeDocument(root, new OutputStreamWriter(myOutputStream))

In the above, the declaration written by XMLSerializer would state "UTF-8", but
the data written by the Writer would be in ISO-8859-1.
c5a2392
@djspiewak djspiewak merged commit c5a2392 into djspiewak:master Sep 25, 2011
@djspiewak
Owner

Merged; thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment