<xsd:restriction> 元素 (complexContent)

定义对 complexContent 定义的约束。

<restriction
  base = QName 
  id = ID 
  {any attributes with non-schema Namespace}...>
Content: (annotation?, (group | all | choice | sequence)?, ((attribute | 
attributeGroup)*, anyAttribute?))
</restriction>

属性

  • base
    在该架构(或由指定的命名空间指示的其他架构)中定义的 complexType 元素的名称。 包含 restriction 元素的元素是从基值所指定的类型派生的。

    基值必须是限定名 (QName)。

    必选项。

  • id
    该元素的 ID。 id 值必须属于类型 ID 并且在包含该元素的文档中是唯一的。

    可选项。

元素信息

出现次数

一次

父元素

complexContent

内容

groupallchoicesequenceattributeattributeGroupanyAttribute

示例

以下示例说明使用 restriction 的复杂类型定义。 复杂类型,即 USAddress,是从常规地址复杂类型派生而来的,其 country 元素固定为 US

<xs:complexType name="address">
  <xs:sequence>
    <xs:element name="street" type="xs:string" />
    <xs:element name="city" type="xs:string" />
    <xs:element name="zipcode" type="xs:integer" />
    <xs:element name="country" type="xs:string" />
  </xs:sequence>
</xs:complexType>

<xs:complexType name="USAddress">
  <xs:complexContent>
    <xs:restriction base="address">
      <xs:sequence>
        <xs:element name="street" type="xs:string" />
        <xs:element name="city" type="xs:string" />
        <xs:element name="zipcode" type="xs:integer" />
        <xs:element name="country" type="xs:string" fixed="US" />
      </xs:sequence>
    </xs:restriction>
  </xs:complexContent>
</xs:complexType>

另请参见

参考

XML 架构 (XSD) 参考
XML 架构元素