How to Change the Charset Encoding of the XML Output
Sometimes you need to use a specific charset for the XML output instead the default UTF-8. You can use the JAXB_ENCODING property of the Marshaller to set it:
MovieLibrary library = ...;
JAXBContext ctx = JAXBContext.newInstance(MovieLibrary.class);
Marshaller marshaller = ctx.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_ENCODING, "iso-8859-15");
marshaller.marshal(new JAXBElement<MovieLibrary>(new QName("movieLibrary"),
MovieLibrary.class, library),
new FileOutputStream("/tmp/library.xml"));