XML Schema simpleType 元素

定義和用法
simpleType 元素定義一個簡單類型,規定與具有純文本內容的元素或屬性的值有關的資訊以及對它們的約束。
元素資訊
- 父元素: attribute, element, list, restriction, schema, union
語法
<simpleType
id=ID
name=NCName
any attributes
>
(annotation?,(restriction|list|union))
</simpleType>
id=ID
name=NCName
any attributes
>
(annotation?,(restriction|list|union))
</simpleType>
(? 符號聲明元素可在 simpleType 元素中出現零次或一次。)
屬性 | 描述 |
---|---|
id | 可選。規定該元素的唯一的 ID。 |
name |
類型名稱。 該名稱必須是在 XML 命名空間規範中定義的無冒號名稱 (NCName)。 如果指定,該名稱在所有 simpleType 和 complexType 元素之間必須是唯一的。 如果 simpleType 元素是 schema 元素的子元素,則為必選項,在其他時候則是不允許的。 |
any attributes | 可選。規定帶有 non-schema 命名空間的任何其他屬性。 |
實例 1
本例聲明 "age" 元素是一個帶有約束的簡單類型。age 的值不能小於 0 或大於 100:
<xs:element name="age">
<xs:simpleType>
<xs:restriction base="xs:integer">
<xs:minInclusive value="0"/>
<xs:maxInclusive value="100"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:simpleType>
<xs:restriction base="xs:integer">
<xs:minInclusive value="0"/>
<xs:maxInclusive value="100"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
