XML Schema simpleType 元素
定義和用法
simpleType 元素定義一個簡單類型,規(guī)定與具有純文本內(nèi)容的元素或?qū)傩缘闹涤嘘P(guān)的信息以及對它們的約束。
元素信息
出現(xiàn)次數(shù) | 無限制 |
父元素 | attribute、element、list、restriction (simpleType)、schema、union |
內(nèi)容 | annotation、list、restriction (simpleType)、union |
語法
<simpleType id=ID name=NCName any attributes > (annotation?,(restriction|list|union)) </simpleType>
(? 符號聲明元素可在 simpleType 元素中出現(xiàn)零次或一次。)
屬性 | 描述 |
---|---|
id | 可選。規(guī)定該元素的唯一的 ID。 |
name |
類型名稱。 該名稱必須是在 XML 命名空間規(guī)范中定義的無冒號名稱 (NCName)。 如果指定,該名稱在所有 simpleType 和 complexType 元素之間必須是唯一的。 如果 simpleType 元素是 schema 元素的子元素,則為必選項,在其他時候則是不允許的。 |
any attributes | 可選。規(guī)定帶有 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>