Binding Schema Basics

Once you’ve got your constraints (I saved my movie database DTD as movies.dtd), you’re ready to create a binding schema for your classes. This will instruct the class generation tool to generate classes, to use a specific Java package, to use collections, and a variety of other options. Although I won’t spend a lot of time on the schemas in this chapter, I’ll give you some basics that will get us through some simple examples. Specifically, I’ll deal with global options here and leave the local options, as well as more advanced features, to Chapter 6.

The Minimum Binding Schema

The first thing that you’ll want to get a handle on is the “minimum binding schema.” This is the least-amount-of-work principle; often, you’ll want to generate classes from your DTD without any changes. To do this, you’ll need to create a binding schema that provides very minimal information to the JAXB schema compiler tool.

The JAXB binding schema is an XML document, and the root element must be xml-java-binding-schema. It must also have a single attribute, version, and currently the only allowed value for this attribute is 1.0-ea.[7]

Tip

The JAXB download comes with the DTD for this schema. It’s located in the [jaxb-root]/doc/ directory and called xjs.dtd.

For a minimal binding schema, you must specify the root element of the DTD being passed in; this allows JAXB to determine which generated object (in source code) is the “top-level” one. This is accomplished through the element element ...

Get Java & XML Data Binding 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.