Developing Java Architecture with JAXB

by Dinesh 2012-07-23 17:02:00

Developing with JAXB (Java Architecture for XML Binding)

JAXB automates mapping between XML documents and Java objects. JAXB marshalling generates an XML document from a Java object that represents an XML document. JAXB unmarshalling turns an XML document into a Java object. JAXB relies on Schemas to specify marshalling and unmarshalling formats for XML documents.

Both render objects that can be used by Java code to access specific parts of an XML document. Both JAXB unmarshalling and XML parsing (using a validating parser) use Schemas to parse documents. However, the difference between parsing and unmarshalling is that while validating parsers use schemas to enforce a structure of an XML document, JAXB can use the same schema as a set of instructions for converting Java objects to an XML document and an XML document to Java objects. JAXB allows easier access to Java objects than either SAX or DOM parsing
can provide. It also allows Java objects that represent XML document objects to be validated before they become XML document objects.

The flexibility of JAXB does come at a price. It would be great if you could feed a schema to JAXB at runtime and have it build XML document object classes on the fly, but that’s not the way that JAXB works (for now, anyway). There are two steps to enabling XML document data binding with JAXB. The first step is to generate a set of classes that are used to handle XML document objects. A Java class is created for each object in a schema. The object classes are generated by JAXB processes and are based on a W3C schema that you provide. The second step uses the generated classes to handle marshalling, manipulation, and unmarshalling of XML documents, with optional schema validation.
838
like
0
dislike
0
mail
flag

You must LOGIN to add comments