background image

Java-toSchema Examples

<< Customization results | Define schema element >>
<< Customization results | Define schema element >>
66
U
SING
JAXB
Calling
getContent
returns the current value of the
Choice
content. The setters
of this
choice
are just like radio buttons; setting one unsets the previously set
one. This class represents the data representing the
choice
.
Additionally, the generated Java interface
FooBarType
, representing the anony-
mous type definition for element
FooBar
, contains a nested interface for the
choice model group containing
phoneNumber
and
speedDial
.
Java-toSchema Examples
The Java-to-Schema examples show how to use annotations to map Java classes
to XML schema.
j2s-create-marshal Example
The j2s-create-marhal example illustrates Java to schema databinding. It demon-
strates marshalling and unmarshalling of JAXB annotated classes. The example
also shows how to enable JAXP 1.3 validation at unmarshal time using a schema
file that was generated from the JAXB mapped classes.
The schema file,
bc.xsd
, was generated with the following commands:
% schemagen src/cardfile/*.java
% cp schema1.xsd bc.xsd
Note that
schema1.xsd
, was copied to
bc.xsd
;
schemagen
does not allow you to
specify a schema name of your choice.
j2s-xmlAccessorOrder Example
The j2s-xmlAccessorOrder example shows how to use the @XmlAccessorOrder
and @XmlType.propOrder annotations to dictate the order in which XML con-
tent is marshalled/unmarshalled by a Java type.
Java-to-Schema maps a JavaBean's properties and fields to an XML Schema
type. The class elements are mapped to either an XML Schema complex type or
an XML Schema simple type. The default element order for a generated schema
type is currently unspecified because Java reflection does not impose a return
order. The lack of reliable element ordering negatively impacts application port-
ability. You can use two annotations, @XmlAccessorOrder and @XmlType.pro-