Java Reference
In-Depth Information
NOTE
Set the following property on your marshaler instance to pretty-print the XML result with indentation:
m.setProperty("jaxb.formatted.output", true);
This is false by default.
Finally, Example 3-11 writes your XML content to a string using the StringWriter class.
Example3-11.Store marshal result in a string using StringWriter
StringWriter sw = new StringWriter();
m.marshal(book, sw);
System.out.println(sw);
JAXBContext is an abstract class, so vendors can implement it as they see fit. JAXB offers a
good combination of flexibility and ease of use. There are other options for doing this sort of
thing, however, including XStream, XMLBeans, and Castor. Of these, XStream is very fast
and does not force you to use annotations on your classes, so in a way it is more flexible than
JAXB. Castor is a more general-purpose framework that provides persistence mapping, but it
is somewhat more limited in terms of strict binding.
XMLBeans was originally written by BEA and eventually donated to the Apache project. Its
most recent release of 2.3 was in June of 2007 and includes XQuery support.
For more alternatives, you could also check out Betwitx and regular Java serialization with
XML.
Search WWH ::




Custom Search