Java Architecture for XML Binding (JAXB) "provides an API and tools that automate the mapping between XML documents and Java obects. JAXB makes XML easy to use by compiling an XML schema into one or more Java technology classes. The combination of the schema derived classes and the binding framework enable one to perform the following operations on an XML document: (1) unmarshal XML content into a Java representation; (2) access, update and validate the Java representation against schema constraint; (3) marshal the Java representation of the XML content into XML content. JAXB gives Java developers an efficient and standard way of mapping between XML and Java code. Java developers using JAXB are more productive because they can write less code themselves and do not have to be experts in XML. JAXB makes it easier for developers to extend their applications with XML and Web Services technologies..." JAXB is being developed through the Java Community Process under JSR-31. [website description 2002-09]
[September 24, 2002] "The Java Architecture for XML Binding (JAXB)." Public Draft. Version 0.7. Status: Pre-FCS. September 12, 2002. 188 pages. Edited by Joseph Fialli and Sekhar Vajjhala. The JAXB Public Draft and API Documentation are available for download. From the JAXB V0.7 Introduction: "The primary components of the XML data-binding facility described in this specification are the binding compiler, the binding framework, and the binding language. (1) The binding compiler transforms, or binds, a source schema to a set of content classes in the Java programming language. As used in this specification, the term schema includes the W3C XML Schema as defined in the XML Schema 1.0 Recommendation [XSD Part 1 and Part 2]. (2) The binding runtime framework provides the interfaces for the functionality of unmarshalling, marshalling, and validation for content classes. (3) The binding language is an XML-based language that describes the binding of a source schema to a Java representation. The binding declarations written in this language specify the details of the package, interfaces and classes derived from a particular source schema..." As of 2002-09, 'Java Architecture for XML Binding (JAXB)' is in Public Draft Review through The Java Community Process. A pre-release version of the Reference Implementation and User's Guide is expected by early Q4 CY2002. [cache JAXB v07]
From the working draft specification:
The XML specification itself describes a sublanguage for writing document-type definitions, or DTDs. Schemas written in this language are by far the most common as of this writing. As schemas go, however, DTDs are fairly weak. They support the definition of simple constraints on structure and content, but provide no real facility for expressing datatypes or complex structural relationships. These deficiencies have motivated proposals to add datatype information to DTDs, such as the DT4DTD datatype-annotation conventions. They have also prompted the creation of more sophisticated schema languages such as XDR, SOX, RELAX, TREX, and, most significantly, the XML Schema language recently defined by the World Wide Web Consortium. This specification aims to support both DTDs and a simple subset of the W3C XML Schema language.
Data binding: Any nontrivial application of XML will be based upon one or more schemas and will involve one or more programs that create, consume, and manipulate documents whose syntax and semantics are governed by those schemas. While it is certainly possible to write such programs using the low-level SAX parser API or the somewhat higher-level DOM parse-tree API, doing so is likely to be tedious and error-prone. The resulting code is also likely to contain many redundancies that will make it difficult to maintain as bugs are fixed and as the schemas evolve. It would be much easier to write XML-enabled programs if we could simply map the components of an XML document to in-memory objects that represent, in an obvious and useful way, the document's intended meaning according to its schema. Of what classes should these objects be instances? In some cases there will be an obvious mapping from schema components to existing classes, especially for common types such as String, Date, Vector, and so forth. In general, however, classes specific to the schema being used will be required. Rather than burden developers with having to write these classes we can generate the classes directly from the schema, thereby creating a Java-level binding of the schema. An XML data-binding facility therefore contains a schema compiler that binds com-ponents of an input schema to derived classes. Each class provides access to the content of the corresponding schema component via a set of JavaBeans-style access (i.e., get and set) methods. Such a facility also provides a binding framework, a runtime API that, in conjunction with the derived classes, supports three primary operations: (1) The unmarshalling of an XML document into a tree of interrelated instances of both existing and schema-derived classes, (2) The marshalling of such content trees back into XML documents, and (3) The validation of content trees against the constraints expressed in the schema.
Schemas describe the structure and meaning of an XML document, in much the same way that a class describes an object in a program. To work with an XML document in a program we would like to map its components directly to a set of objects that reflect the document's meaning according to its schema. We can achieve this by compiling the schema into a set of derived classes that handle all the details of marshalling and unmarshalling and also ensure that only valid documents will be produced and consumed. Data binding thus allows XML-enabled programs to be written at the same conceptual level as the documents they manipulate, rather than at the more primitive level parser events or parse trees.
"The primary components of the XML data-binding facility described in this specification are the schema compiler, the binding framework, and the binding language. (1) The schema compiler transforms, or binds, a source schema to a set of derived classes. As used in this specification, the term schema includes the document-type definition language of the XML 1.0 specification. (2) The binding framework is a set of public interfaces and classes upon which derived classes rely to implement the operations of unmarshalling, mar-shalling, and validation. (3) The binding language is an XML-based language that describes the binding of a source schema to a set of derived classes. A binding schema written in this language specifies the details of the classes derived from a particular source schema.
From the User's Guide:
JAXB provides a fast, convenient way to create a two-way mapping between XML documents and Java objects. Given a schema, which specifies the structure of XML data, the JAXB compiler generates a set of Java classes containing all the code to parse XML documents based on the schema. An application that uses the generated classes can build a Java object tree representing an XML document, manipulate the content of the tree, and re-generate XML documents from the tree, all without requiring the developer to write complex parsing and processing code.
Applications written in the Java programming language are portable: Any system with a Java Virtual Machine 1 can run the bytecode produced by compiling a Java application. With the portable code that Java technology provides, XML is even more useful in the context of sharing data between applications. Applications, especially web-based applications, need the support of Java technology to parse and process the data in a platform-independent manner. Likewise, Java applications need the platform-independent data format that XML provides in order to communicate and share information.
Essentially, JAXB provides a bridge between these two complementary technologies. JAXB includes a compiler that maps a schema to a set of Java classes. Once you have your classes, you can build Java object representations of the XML data that follow the rules that the schema defines. Just as an XML document is an instance of a schema, a Java object is an instance of a class. Thus, JAXB allows you to create Java objects at the same conceptual level as the XML data. Representing your data in this way allows you to manipulate it in the same manner you manipulate Java objects, making it easier to create applications to process XML data. Once you have your data in the form of Java objects, it is easy to access it. In addition, after working with the data, you can write the Java objects to a new XML document. With the easy access to XML data that JAXB provides, you only need to write the applications that will actually use the data, rather than spend time writing code to format the data.
- Java Architecture for XML Binding (JAXB)
- Java Web Services Developer Pack
- Java Specification Request JSR-31. XML Data Binding Specification.
- [June 2001] The Java Architecture for XML Binding User Guide. 80 pages, PDF. [cache]
- Download JAXB Early Access Implementation v1.0
- Java Architecture for XML Binding Working Draft Specification Version 0.21. Working-Draft Specification. May 30, 2001. 132 pages.
- An XML Data-Binding Facility for the Java Platform [Design note]
- Comments: send email to email@example.com
- See also [Adelard] XML Data Binding Specification."
[January 14, 2003] "XML in Java. Data Binding, Part 1: Code Generation Approaches -- JAXB and More. Generating Data Classes from DTDs or Schemas." By Dennis M. Sosnoski (President, Sosnoski Software Solutions, Inc). From IBM developerWorks, XML zone. January 2003. ['Explore your XML data binding options as Enterprise Java technology expert Dennis Sosnoski shows you several approaches -- JAXB, Castor, JBind, Quick, and Zeus. Enterprise Java expert Dennis Sosnoski looks at several XML data binding approaches using code generation from W3C XML Schema or DTD grammars for XML documents. He starts out with the long-awaited JAXB standard now nearing release through the Java Community Process (JCP), then summarizes some of the other frameworks that are currently available. Finally, he discusses how and when you can best apply code generation from a grammar in your applications.'] "Data binding provides a simple and direct way to use XML in your Java Platform applications. With data binding your application can largely ignore the actual structure of XML documents, instead working directly with the data content of those documents. This isn't suitable for all applications, but it is ideal for the common case of applications that use XML for data exchange. Data binding can also provide other benefits beyond programming simplicity. Since it abstracts away many of the document details, data binding usually requires less memory than a document model approach (such as DOM or JDOM) for working with documents in memory. You'll also find that the data binding approach gives you faster access to data within your program than you would get with a document model, since you don't need to go through the structure of the document to get at the data. Finally, special types of data such as numbers and dates can be converted to internal representations on input, rather than being left as text; this allows your application to work with the data values much more efficiently... In Part 2 I'll show the performance results from testing these data binding frameworks on some sample documents. These results cover both generated code and mapped binding approaches, with document models included for comparison..."
[January 09, 2003] "The JAXB API." By Kohsuke Kawaguchi. From XML.com. January 08, 2003. ['Kohsuke Kawaguchi explores the API of Sun's Java Architecture for XML Binding.'] "Sun has recently released version 0.75 of the Java Architecture for XML Binding (JAXB), as well as its reference implementation. JAXB consists of two parts. First, JAXB contains a compiler that reads a schema and produces the equivalent Java object model. This generated object model captures the structure of XML better than general-purpose APIs like DOM or SAX, making it a lot easier to manipulate XML content. The second part is an API, through which applications communicate with generated code. This API hides provider-specific implementation code from applications and also provides a uniform way to do basic operations, such as marshalling or unmarshalling... in this article, I'll introduce the JAXB API. We'll examine the design of the API and discuss its shortcomings; consider JAXB in the context of the Java-XML universe; and, finally, we'll learn if JAXB can evolve to meet expected future needs. While you can use JAXB without knowing how a schema is mapped to Java or how to use customizations, you cannot use JAXB if you don't know the API. Further, the API is here to stay. The way a JAXB binding compiler maps W3C XML Schema to Java can be changed more drastically and easily by utilizing the version attribute and through the extensibility framework. Thanks to this extensibility framework, vendors are free to go beyond the baseline functionality in the specification. Similarly, the JAXB specification can extend the supported subset of W3C XML Schema in the future or even support other schema languages. But to do this, the API needs to be sufficiently solid and flexible now. For these reasons, the API deserves thorough consideration... One of the concerns raised in the community is that JAXB can't be used to bind existing code to XML, since it can only produce Java classes from a schema, not the other way around. While this is indeed true for the current version of JAXB, we have seen that the API itself doesn't have this constraint. Nothing prevents tools from using this API to map existing Java classes to XML. In fact, the interface used by Castor to do this Java-centric mapping is very close to JAXB API, so it won't be hard to change it to use this API. Similarly, the current version of JAXB only deals with W3C XML Schema. But, again, the API has virtually no dependency on any particular schema language. Therefore, a tool can hijack the JAXB API for its choice of schema language. It would be good to see a RELAX NG-aware databinding tool (like Relaxer) use the JAXB API..."
[December 23, 2002] "JAXB Revisited." By Daniel F. Savarese. In Java Pro Magazine (February 2003). ['With an updated version and specification draft now available, get reacquainted with JAXB.'] "The JAXB specification has benefited from developer feedback over time, sacrificing some features and adding new ones in the process. Let's see what it looks like today, with a reasonable assurance that the changes between the beta and final release will not be great... As a quick review for the uninitiated, JAXB defines an architecture for binding XML schemata to Java objects. These bindings allow you to unmarshal XML documents into a hierarchy of Java objects and marshal the Java objects into XML with minimal effort. If you work a lot with XML, you know how tedious it can be to write Simple API for XML (SAX) or Document Object Model (DOM) code to convert XML into Java objects that mean something to your program. JAXB generates code automatically so you can go about the business of processing data instead of parsing it. The basic JAXB design remains the same as in the early access release, but the details have changed. You still have to define a schema binding that is compiled by a schema-binding compiler. The schema-binding compiler generates Java interfaces and classes based on the binding. Whereas early versions of JAXB supported only Document Type Definitions (DTDs) and required that a schema binding be defined separately, the latest version of JAXB supports XML schema definitions and allows additional binding declarations to be defined inside of the schema using XML schema annotations. The JAXB specification also allows bindings to be defined in a separate document, but the beta release of the reference implementation supports only schema annotations... The first half of the JAXB architecture is the schema-binding system. The second half is the Java API contained in the javax.xml.bind package, with which you make use of the classes generated by the schema compiler. The JAXB APIs have evolved considerably and have arrived at a design that cleanly separates functionality. The javax.xml.bind package defines a set of interfaces and one class, JAXBContext, which acts as an entry point to the rest of the API functionality. The three most important interfaces are Unmarshaller, Marshaller, and Validator. The Unmarshaller interface defines a set of unmarshal() methods for unmarshalling XML data into a Java object. The Marshaller interface defines a set of marshal() methods for marshalling Java objects into XML data. The Validator interface defines methods for validating a Java object hierarchy against the XML schema from which it is derived as well as methods for adding event handlers to monitor and react to the validation process... Turning XML into a Java object is as simple as creating an Unmarshaller and invoking an unmarshal() method. Converting a Java object into XML is as simple as creating a Marshaller and invoking a marshal() method. Validating an object hierarchy before marshalling is as simple as creating a Validator and invoking a validator method... Despite the existence of other XML marshalling solutions, JAXB is good at what it sets out to do, and as a result you can expect to write far less SAX and DOM code in the future..." See: (1) Java Architecture for XML Binding (JAXB) 1.0 Beta Implementation; (2) JAXB website.
[March 22, 2002] "Java Architecture for XML Binding (JAXB): A Primer." By Tai-Wei Lin. From [Sun] Java Developer Connection. March 13, 2002. "This article introduces you to the basics of Java Architecture for XML Binding (JAXB) Early Access Implementation v 1.0. You will learn a few basic uses of the API and tools that the EA v 1.0 provides. This paper provides brief explanations on how to create simple binding codes using the API and tools. In addition, this paper also discusses a few situations where JAXB shows its strengths, and is intended for developers who have working understanding of the Java programming language, are familiar with XML, and interested in getting a brief introduction to JAXB. Introduction to JAXB Java Architecture for XML Binding (JAXB) provides an API and tool that allow automatic two-way mapping between XML documents and Java objects. With a given Document Type Definition (DTD) and a schema definition, the JAXB compiler can generate a set of Java classes that allow developers to build applications that can read, manipulate and recreate XML documents without writing any logic to process XML elements. The generated codes provide an abstraction layer by exposing a public interface that allows access to the XML data without any specific knowledge about the underlying data structure. In addition to DTD support, future versions of JAXB will add support for other schema languages, such as the W3C XML Schema. These features enable the JAXB to provide many benefits for the developers..."