Export (0) Print
Expand All

<xsd:union> Element

Defines a collection of multiple simpleType definitions.

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

Attributes

id

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

Optional.

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.

Optional.

Element Information

Number of occurrences

One time

Parent elements

simpleType

Contents

annotation, simpleType

Example

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

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

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

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

Example

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:annotation>
    <xs:documentation>for maxOccurs</xs:documentation>
  </xs:annotation>
  <xs:union memberTypes="nonNegativeInteger">
   <xs:simpleType>
    <xs:restriction base="xs:NMTOKEN">
     <xs:enumeration value="unbounded"/>
    </xs:restriction>
   </xs:simpleType>
  </xs:union>
 </xs:simpleType>

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

Community Additions

ADD
Show:
© 2014 Microsoft