Chapter 11. Data Binding with JAXB
As I mentioned at the end of the last chapter, data binding is an XML processing technique that
eliminates references to XML nodes from your code. Instead of working with elements and
attributes, your code uses classes named Customer
and PurchaseOrder
. This first means that you have to
define the structure of your XML documents using a schema, typically
either an XML Schema or a DTD. To bind this schema to specific Java
classes, which could include generating those classes from the schema,
you’ll use a data binding framework. These are generally composed of
code-generation tools to build Java classes from a schema and a runtime
library that converts an XML document into a tree of Java objects (and
vice versa). There are many data binding frameworks available for Java. In
this chapter, we’ll look specifically at one: the Java Architecture for XML Binding ( JAXB).
Data Binding Basics
Before getting into the specifics of JAXB, it will be helpful to take a look at the concepts that underlie data binding in general. Fundamentally, data binding is similar to the document object model APIs we’ve discussed—DOM, JDOM, and dom4j—in that it defines an association, referred to as a binding, between an XML document and a tree of Java objects. A tree of Java objects can be created from an XML document and vice versa. The difference is that when data binding, the Java objects mapped to the document are instances not of generic interfaces representing elements ...
Get Java and XML, 3rd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.