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
xml-java-binding-schema. It must also have a
version, and currently the only
allowed value for this attribute is
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
element element ...