Generate an XML Document from an Object Model with JAXB 2
Learn how to get an XML document from your Java object model using JAXB 2. With annotations, you can also customize the document and use adapters to format data.
by Antonio Goncalves
March 26, 2007
ava offers various ways to manipulate XML, including the following:
Use XML serialization with java.beans.XMLEncoder, which generates an XML representation of a Java Bean in the same way ObjectOutputStream can be used to create binary representation of Serializable objects.
Use a dedicated library like XStream
Play directly with SAX (Simple API for XML) or DOM (Document Object Model) through the JAXP API.
Yet despite XML and Java technology being natural partners in data exchange, mapping a Java object model into XML and vice versa can be a mystery. Consider JAXB as your solution. JAXB (Java Architecture for XML Binding) enables you to perform XML-to-Java data binding and generate Java classes from XML schemas and vice-versa. It's portable, easy to use, and it offers functionalities such as XML validation and customization using annotation and adapters. (Figure 1 illustrates the uses of JAXB.)
It's quick, easy and you get access to all the articles on DevX.
This registration/login is to allow you to read articles on devx.com. Already a member?
To become a member of DevX.com create your Member Profile by completing the form below. Membership is free!