XML Schema simpleType 元素
定义和用法
simpleType 元素定义一个简单类型,规定与具有纯文本内容的元素或属性的值有关的信息以及对它们的约束。
元素信息
出现次数 | 无限制 |
父元素 | attribute、element、list、restriction (simpleType)、schema、union |
内容 | annotation、list、restriction (simpleType)、union |
语法
<simpleType id=ID name=NCName attributes > (annotation?,(restriction|list|union)) </simpleType>
(? 符号声明元素可在 simpleType 元素中出现零次或一次。)
属性 | 描述 |
---|---|
id | 可选。规定该元素的唯一的 ID。 |
name |
类型名称。 该名称必须是在 XML 命名空间规范中定义的无冒号名称 (NCName)。 如果指定,该名称在所有 simpleType 和 complexType 元素之间必须是唯一的。 如果 simpleType 元素是 schema 元素的子元素,则为必选项,在其他时候则是不允许的。 |
attributes | Optional. Specifies any other attributes with non-schema namespaces. |
Instance
Example 1
In this example, the "age" element is declared as a simple type with constraints. The value of age cannot be less than 0 or greater than 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>