XML Schema simpleType 元素

定义和用法

simpleType 元素定义一个简单类型,规定与具有纯文本内容的元素或属性的值有关的信息以及对它们的约束。

元素信息

出现次数 无限制
父元素 attribute、element、list、restriction (simpleType)、schema、union
内容 annotation、list、restriction (simpleType)、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>