2.2.10 Defining a Type Union
A simple type may also be constructed as a union of two or more
simple types.
<xsd:simpleType name="SpeedOrNumberType">
<xsd:union>
<xsd:simpleType>
<xsd:restriction base="xsd:int">
</xsd:restriction>
</xsd:simpleType>
<xsd:simpleType>
<xsd:restriction base="xsd:string">
<xsd:pattern value="\+?\d+"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:union>
</xsd:simpleType>
In Java, there is no convenient way of expressing unions of simple types.
The JAXB compiler simply inserts Java's String
type wherever
the union type is used and leaves it up to the application programmer
to handle the rest. Try to avoid xsd:union
.