XML Schema union 元素

定義和用法

union 元素定義多個 simpleType 定義的集合。

元素信息

出現次數 一次
父元素 simpleType
內容 annotation、simpleType

語法

<union
id=ID
memberTypes="list of QNames"
any attributes
>
(annotation?,(simpleType*))
</union>

(? 符號聲明在 union 元素中該元素可出現零次或一次。)

屬性 描述
id 可選。規定該元素的唯一的 ID。
memberTypes 可選。規定在 schema 中定義的內置數據類型或 simpleType 元素的名稱列表。
any attributes 可選。規定帶有 non-schema 命名空間的任何其他屬性。

實例

例子 1

本例是一個合并了兩個簡單類型的簡單類型:

<xs:element name="jeans_size">
  <xs:simpleType>
    <xs:union memberTypes="sizebyno sizebystring" />
  </xs:simpleType>
</xs:element>
<xs:simpleType name="sizebyno">
  <xs:restriction base="xs:positiveInteger">
    <xs:maxInclusive value="42"/>
  </xs:restriction>
</xs:simpleType>
<xs:simpleType name="sizebystring">
  <xs:restriction base="xs:string">
    <xs:enumeration value="small"/>
    <xs:enumeration value="medium"/>
    <xs:enumeration value="large"/>
  </xs:restriction>
</xs:simpleType>