Annotation Type XmlType

The @XmlType annnotation can be used with the following program
elements:

a top level class

an enum type

See "Package Specification" in javax.xml.bind.package javadoc for
additional common information.

Mapping a Class

A class maps to a XML Schema type. A class is a data container for
values represented by properties and fields. A schema type is a
data container for values represented by schema components within a
schema type's content model (e.g. model groups, attributes etc).

To be mapped, a class must either have a public no-arg
constructor or a static no-arg factory method. The static factory
method can be specified in factoryMethod() and
factoryClass() annotation elements. The static factory
method or the no-arg constructor is used during unmarshalling to
create an instance of this class. If both are present, the static
factory method overrides the no-arg constructor.

A class maps to either a XML Schema complex type or a XML Schema simple
type. The XML Schema type is derived based on the
mapping of JavaBean properties and fields contained within the
class. The schema type to which the class is mapped can either be
named or anonymous. A class can be mapped to an anonymous schema
type by annotating the class with @XmlType(name="").

Either a global element, local element or a local attribute can be
associated with an anonymous type as follows:

global element: A global element of an anonymous
type can be derived by annotating the class with @XmlRootElement. See Example 3 below.

local element: A JavaBean property that references
a class annotated with @XmlType(name="") and is mapped to the
element associated with the anonymous type. See Example 4
below.

attribute: A JavaBean property that references
a class annotated with @XmlType(name="") and is mapped to the
attribute associated with the anonymous type. See Example 5 below.

Mapping to XML Schema Complex Type

If class is annotated with @XmlType(name="") , it
is mapped to an anonymous type otherwise, the class name maps
to a complex type name. The XmlName() annotation element
can be used to customize the name.

Properties and fields that are mapped to elements are mapped to a
content model within a complex type. The annotation element
propOrder() can be used to customize the content model to be
xs:all or xs:sequence. It is used for specifying
the order of XML elements in xs:sequence.

Properties and fields can be mapped to attributes within the
complex type.

The targetnamespace of the XML Schema type can be customized
using the annotation element namespace().

Mapping class to XML Schema simple type

A class can be mapped to a XML Schema simple type using the
@XmlValue annotation. For additional details and examples,
see @XmlValue annotation type.

The following table shows the mapping of the class to a XML Schema
complex type or simple type. The notational symbols used in the table are:

-> : represents a mapping

[x]+ : one or more occurances of x

[ @XmlValue property ]: JavaBean property annotated with
@XmlValue

X : don't care

Target

propOrder

ClassBody

ComplexType

SimpleType

Class

{}

[property]+ -> elements

complexcontentxs:all

Class

non empty

[property]+ -> elements

complexcontentxs:sequence

Class

X

no property -> element

complexcontentempty sequence

Class

X

1 [ @XmlValue property] && [property]+
->attributes

simplecontent

Class

X

1 [ @XmlValue property ]&& no properties
-> attribute

simpletype

Mapping an enum type

An enum type maps to a XML schema simple type with enumeration
facets. The following annotation elements are ignored since they
are not meaningful: propOrder() , factoryMethod() ,
factoryClass() .

Element Detail

name

propOrder

Specifies the order for XML Schema elements when class is
mapped to a XML Schema complex type.

Refer to the table for how the propOrder affects the
mapping of class

The propOrder is a list of names of JavaBean properties in
the class. Each name in the list is the name of a Java
identifier of the JavaBean property. The order in which
JavaBean properties are listed is the order of XML Schema
elements to which the JavaBean properties are mapped.

All of the JavaBean properties being mapped to XML Schema elements
must be listed.

A JavaBean property or field listed in propOrder must not
be transient or annotated with @XmlTransient.