∟"simpleType" Components with "union" Child Components
This section describes the 'union' child component in 'simpleType' component. 'union' child components are used to create a union of value spaces from multiple member datatypes.
"union" child component in a "simpleType" component offers a different way of defining a new simple datatype by
combining value spaces from multiple other simple datatypes.
Here is an XSD template showing you how to use the "union" as a child component in a "simpleType" component:
Format 1:
<simpleType ...>
<union memberTypes="member_type_list">
</simpleType>
Format 2:
<simpleType ...>
<union>
<simpleType ...>
definition of member datatype 1
</simpleType>
<simpleType ...>
definition of member datatype 2
</simpleType>
...
</union>
</simpleType>
Some notes on using the "union" component:
memberTypes="member_type_list" - Optional attribute to specify multiple datatypes
to be used as members of the union.
If not provided, member datatypes must be defined with child "simpleType" components.
Child "simpleType" components are always allowed to add more member datatypes,
even memberTypes="member_type_list" is provided.
For example, the following XSD document uses "union" components to define 2 new simple datatypes:
When validating this XML document with my XsdSchemaValidator.java program presented earlier in the book,
I get these errors:
c:\Progra~1\Java\jdk1.7.0_07\bin\java XsdSchemaValidator
union_simpleType_test.xsd union_simpleType_test.xml
Error:
Line number: 12
Column number: 43
Message: cvc-datatype-valid.1.2.3: ' Unit:Million ' is not a
valid value of union type
'#AnonType_MixedDataUnion_SimpleType_Test'.
Error:
Line number: 12
Column number: 43
Message: cvc-type.3.1.3: The value ' Unit:Million ' of element
'MixedData' is not valid.
Error:
Line number: 19
Column number: 25
Message: cvc-datatype-valid.1.2.3: ' 13 ' is not a valid value of
union type '#AnonType_MonthUnion_SimpleType_Test'.
Error:
Line number: 19
Column number: 25
Message: cvc-type.3.1.3: The value ' 13 ' of element 'Month' is
not valid.
Error:
Line number: 20
Column number: 26
Message: cvc-datatype-valid.1.2.3: ' may ' is not a valid value
of union type '#AnonType_MonthUnion_SimpleType_Test'.
Error:
Line number: 20
Column number: 26
Message: cvc-type.3.1.3: The value ' may ' of element 'Month' is
not valid.
Failed with errors: 6