<xsd:union> Element

Defines a collection of multiple simpleType definitions.

  id = ID 
  memberTypes = List of QNames 
  {any attributes with non-schema Namespace}...>
Content: (annotation?, (simpleType*))


  • id
    The ID of this element. The id value must be of type ID and be unique within the document containing this element.


  • memberTypes
    The list of names of built-in data types or simpleType elements defined in this schema (or another schema indicated by the specified namespace). The simpleType element containing the union element is derived from the simple types specified by the memberTypes value. The values in memberTypes must be qualified names (QNames).

    For simple type union definitions, the list of simple types is the union of the contents of memberTypes (which is itself a list of simple types) and each of the child simpleType element definitions under the union element. See the second example later in this topic.

    The memberTypes attribute is opposite of the itemType attribute for the list element which is mutually exclusive to the simpleType element child of the list element.


Element Information

Number of occurrences

One time

Parent elements



annotation, simpleType


The following example shows a simple type that is a union of two simple types.

<xs:attribute name="fontsize">
    <xs:union memberTypes="fontbynumber fontbystringname" />

<xs:simpleType name="fontbynumber">
  <xs:restriction base="xs:positiveInteger">
    <xs:maxInclusive value="72"/>

<xs:simpleType name="fontbystringname">
  <xs:restriction base="xs:string">
    <xs:enumeration value="small"/>
    <xs:enumeration value="medium"/>
    <xs:enumeration value="large"/>


The following example shows a simple type definition that is a union of all nonnegative integers and the NMTOKEN "unbounded". (This is from the schema in the W3C XML Schema Part 1: Structures specification.)

<xs:simpleType name="allNNI">
    <xs:documentation>for maxOccurs</xs:documentation>
  <xs:union memberTypes="nonNegativeInteger">
    <xs:restriction base="xs:NMTOKEN">
     <xs:enumeration value="unbounded"/>

Other Resources

For more information see the W3C XML Schema Part 1: Structures Recommendation at www.w3.org/TR/2001/REC-xmlschema-1-20010502/\#element-all.

See Also


XML Schemas (XSD) Reference
XML Schema Elements