How to Serialize XML Into a String
In general, it is not recommended to serialize XML into a String. XML is defined as a binary format, and ideally you should write handle it as such. When storing an 'XML string' you need to be aware of the character encoding defined in the XML prolog. If you write your 'XML string' in the wrong encoding you will run into trouble.
Now, after the obligatory warning, it is possible and actually quite easy to write your JAXB tree into an 'XML string':
MovieLibrary ml = ...;
StringWriter writer = new StringWriter();
JAXB.marshall(ml, writer);
String xmlText = writer.toString();

