A JAXB Tutorial
Wolfgang Laun
Thales Rail Signalling Solutions GesmbH
1 Introduction2 Writing an XML Schema for JAXB
2.1 XML Schema Types
2.2 JAXB Examples
3 Unmarshalling and Using the Data2.2 JAXB Examples
2.2.1 Defining an Integer Range Type
2.2.2 Numeric Types
2.2.3 Defining a String with Length Limits
2.2.4 Defining a String Type Restricted By Pattern
2.2.5 Date and Time
2.2.6 Binary Data
2.2.7 Defining a List of Integers
2.2.8 Defining Other Lists
2.2.9 Defining an Enumeration
2.2.10 Defining a Type Union
2.2.11 Defining Types for XML Elements Without Content
2.2.12 Defining Types for XML Elements With Content
2.2.14 Substitution Groups
2.2.15 Referring to Another XML Element
2.2.16 Elements With Any Type
2.2.17 Image Data
2.3 Hints on Writing XML Schemas2.2.2 Numeric Types
2.2.3 Defining a String with Length Limits
2.2.4 Defining a String Type Restricted By Pattern
2.2.5 Date and Time
2.2.6 Binary Data
2.2.7 Defining a List of Integers
2.2.8 Defining Other Lists
2.2.9 Defining an Enumeration
2.2.10 Defining a Type Union
2.2.11 Defining Types for XML Elements Without Content
2.2.12 Defining Types for XML Elements With Content
2.2.12.1 Content: A Value
2.2.12.2 Content: An Ordered Set of Elements
2.2.12.3 Content: An Unordered Set of Elements
2.2.12.4 Content: Alternative Elements
2.2.12.5 Content: A Homogeneous List of Elements
2.2.12.6 Content: A Mixed List of Elements
2.2.12.7 Mixed Content
2.2.12.8 No Value
2.2.13 Defining Subtypes2.2.12.2 Content: An Ordered Set of Elements
2.2.12.3 Content: An Unordered Set of Elements
2.2.12.4 Content: Alternative Elements
2.2.12.5 Content: A Homogeneous List of Elements
2.2.12.6 Content: A Mixed List of Elements
2.2.12.7 Mixed Content
2.2.12.8 No Value
2.2.14 Substitution Groups
2.2.15 Referring to Another XML Element
2.2.16 Elements With Any Type
2.2.17 Image Data
2.3.1 Don't Use Anonymous Types
2.3.2 Common Schema Definitions
2.3.3 A Note on Groups
2.3.4 Conserving Compatibility
2.3.5 Spurious Classes
2.3.6 Avoid Unnecessary
2.3.2 Common Schema Definitions
2.3.3 A Note on Groups
2.3.4 Conserving Compatibility
2.3.5 Spurious Classes
2.3.6 Avoid Unnecessary
JAXBElement<?>3.1 Unmarshalling
3.2 Using the Element Tree
3.3 Validation
3.4 Validation Event Handling
3.5 The JAXB Context
4 Building and Marshalling an XML Document3.2 Using the Element Tree
3.3 Validation
3.4 Validation Event Handling
3.5 The JAXB Context
4.1 The Object Factory
4.2 Assembling Document Tree Nodes
4.3 Assembling Data with Links (ID, IDREF)
4.4 Last Resort: Assembling a Java Object
4.5 Calling
5 Customizing4.2 Assembling Document Tree Nodes
4.3 Assembling Data with Links (ID, IDREF)
4.4 Last Resort: Assembling a Java Object
4.5 Calling
marshal5.1 Reasons for Customizing
5.2 Defining Package Names
5.3 Overriding Names
5.4 Adding Documentation
5.5 Interning Strings
5.6 Overriding the Datatype
6 JAXB Annotations5.2 Defining Package Names
5.3 Overriding Names
5.4 Adding Documentation
5.5 Interning Strings
5.6 Overriding the Datatype
6.1 How a Schema Mapping Is Implemented
6.2 A Survey Of JAXB Annotations
6.2 A Survey Of JAXB Annotations
6.2.1 Top-level Elements:
6.2.2 Annotation for Classes:
6.2.3 Annotations for the Schema:
6.2.4 The Object Factory:
6.2.5 Controlling Element Selection:
6.2.6 Class Inclusion:
6.2.7 Annotations for Fields
6.2.9 Type Adapters:
6.2.10 Type Mapping:
6.2.11 Annotations for Object References:
XmlRootElement6.2.2 Annotation for Classes:
XmlType6.2.3 Annotations for the Schema:
XmlSchema6.2.4 The Object Factory:
XmlRegistry, XmlElementDecl6.2.5 Controlling Element Selection:
XmlAccessorType, XmlTransient6.2.6 Class Inclusion:
XmlSeeAlso6.2.7 Annotations for Fields
6.2.7.1 The Annotation
6.2.7.2 The Annotation
6.2.7.3 Class Fields as Attributes:
6.2.7.4 Mapping a Class to Simple Content or Simple Type:
6.2.7.5 Collecting Unspecified Attributes:
6.2.7.6 Collecting Unspecified Elements:
6.2.7.7 Wrapping Repeated Elements:
6.2.7.8 Annotations for Mixed Content:
6.2.8 Annotations for Enums: XmlElement6.2.7.2 The Annotation
XmlList6.2.7.3 Class Fields as Attributes:
XmlAttribute6.2.7.4 Mapping a Class to Simple Content or Simple Type:
XmlValue6.2.7.5 Collecting Unspecified Attributes:
XmlAnyAttribute6.2.7.6 Collecting Unspecified Elements:
XmlAnyElement6.2.7.7 Wrapping Repeated Elements:
XmlElementWrapper6.2.7.8 Annotations for Mixed Content:
XmlElementRef, XmlMixedXmlEnum, XmlEnumValue6.2.9 Type Adapters:
XmlJavaTypeAdapter6.2.10 Type Mapping:
XmlSchemaType6.2.11 Annotations for Object References:
XmlID, XmlIDREF