users@jaxb.java.net

Re: Handling Special Chars

From: Dmitri Colebatch <colebatchd_at_gmail.com>
Date: Mon, 3 Oct 2005 08:58:00 +1000

On 03/10/05, Robert Lowe <robertmlowe_at_rmlowe.com> wrote:
> FileWriter writer = new FileWriter("myfile.xml");
> marshaller.marshal(myJaxbObject, writer);
>
> The problem here is that, by default, JAXB will include an XML
> declaration something like:
>
> <?xml version="1.0" encoding="UTF-8" ?>
>
> However, the FileWriter uses the platform-specific default character
> encoding, which almost certainly *won't* be UTF-8, resulting in a
> mismatch between the declared encoding and the actual encoding. The safe
> way to do this would be:
>
> FileOutputStream os = new FileOutputStream("myfile.xml");
> marshaller.marshal(myJaxbObject, os);

XMLBeans gets around this by only including the xml decl if you use
the OutputStream. Perhaps this is something that jaxb could consider.

cheers
dim