Skip to content
This repository has been archived by the owner on May 15, 2019. It is now read-only.

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

Merged
merged 1 commit into from Sep 25, 2011

Conversation

hvesalai
Copy link

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.

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.
@djspiewak djspiewak merged commit c5a2392 into djspiewak:master Sep 25, 2011
@djspiewak
Copy link
Owner

Merged; thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants