How to Create Nicely Formatted XML
By default, JAXB creates compact XML that can not easily be read by humans. If you want to format it more nicely, you need to set the JAXB_FORMATTED_OUTPUT property of the Marshaller:
MovieLibrary library = ...;
JAXBContext ctx = JAXBContext.newInstance(MovieLibrary.class);
Marshaller marshaller = ctx.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
marshaller.marshal(new JAXBElement<MovieLibrary>(new QName("movieLibrary"),
MovieLibrary.class, library),
new FileOutputStream("/tmp/library.xml"));

