background image

Binding Declaration Files

<< Building and Running the Example | Schema Name and Schema Node >>
<< Building and Running the Example | Schema Name and Schema Node >>

Binding Declaration Files

Binding Declaration Files
The following sections provide information about binding declaration files:
"JAXB Version, Namespace, and Schema Attributes" on page 533
"Global and Schema Binding Declarations" on page 534
"Class Declarations" on page 535
JAXB Version, Namespace, and Schema Attributes
All JAXB binding declarations files must begin with:
JAXB version number
Namespace declarations
Schema name and node
The version, namespace, and schema declarations in bindings.xjb are as follows:
<jxb:bindings version=
"1.0"
xmlns:jxb=
"http://java.sun.com/xml/ns/jaxb"
xmlns:xs=
"http://www.w3.org/2001/XMLSchema">
<jxb:bindings schemaLocation=
"po.xsd" node="/xs:schema">
...
binding-declarations
...
</jxb:bindings>
<!-- schemaLocation=
"po.xsd" node="/xs:schema" -->
</jxb:bindings>
JAXB Version Number
An XML file with a root element of <jaxb:bindings> is considered an external binding file. The
root element must specify the JAXB version attribute with which its binding declarations must
comply; specifically the root <jxb:bindings> element must contain either a <jxb:version>
declaration or a version attribute. By contrast, when making binding declarations inline, the
JAXB version number is made as attribute of the <xsd:schema> declaration:
<xsd:schema xmlns:xsd=
"http://www.w3.org/2001/XMLSchema"
xmlns:jxb=
"http://java.sun.com/xml/ns/jaxb"
jxb:version=
"1.0">
Namespace Declarations
As shown in
"JAXB Version, Namespace, and Schema Attributes" on page 533
, the namespace
declarations in the external binding declarations file include both the JAXB namespace and the
XMLSchema namespace. Note that the prefixes used in this example could in fact be anything
you want; the important thing is to consistently use whatever prefixes you define here in
subsequent declarations in the file.
Customizing JAXB Bindings
Chapter 17 · Binding between XML Schema and Java Classes
533