A JAXB Tutorial
Wolfgang Laun
Thales Rail Signalling Solutions GesmbH

1 Introduction
1.1 About JAXB
1.2 Overview
1.3 Hello World
2 Writing an XML Schema for JAXB
2.1 XML Schema Types
2.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.13 Defining Subtypes
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 Schemas
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 JAXBElement<?>
3 Unmarshalling and Using the Data
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 Document
4.1 The Object Factory
4.2 Assembling Document Tree Nodes
4.3 Assembling Data with Links (ID, IDREF)
4.3.1 One Element per Identification
4.3.2 Preserving Object Identity
4.4 Last Resort: Assembling a Java Object
4.5 Calling marshal
5 Customizing
5.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
5.6.1 Replacing the Conversions
5.6.2 Replacing a Simple Type
6 JAXB Annotations
6.1 How a Schema Mapping Is Implemented
6.2 A Survey Of JAXB Annotations
6.2.1 Top-level Elements: XmlRootElement
6.2.2 Annotation for Classes: XmlType
6.2.3 Annotations for the Schema: XmlSchema
6.2.4 The Object Factory: XmlRegistry, XmlElementDecl
6.2.5 Controlling Element Selection: XmlAccessorType, XmlTransient
6.2.6 Class Inclusion: XmlSeeAlso
6.2.7 Annotations for Fields
6.2.8 Annotations for Enums: XmlEnum, XmlEnumValue
6.2.9 Type Adapters: XmlJavaTypeAdapter
6.2.10 Type Mapping: XmlSchemaType
6.2.11 Annotations for Object References: XmlID, XmlIDREF