举报投诉联系我们 手机版 热门标签 名动网
您的位置:名动网 > XML Schema restriction 元素

XML Schema restriction 元素

2023-04-09 10:20 XMLSchema教程

 XML Schema restriction 元素

XML Schema restriction 元素


XML Schema 参考手册 完整 XML Schema 参考手册

定义和用法

restriction 元素定义对 simpleType、simpleContent 或 complexContent 定义的约束。

元素信息

  • 父元素: simpleType, simpleContent, complexContent

语法

<restriction
id=ID
base=QName
any attributes
>

Content for simpleType:
(annotation?,(simpleType?,(minExclusive|minInclusive|
maxExclusive|maxInclusive|totalDigits|fractionDigits|
length|minLength|maxLength|enumeration|whiteSpace|pattern)*))

Content for simpleContent:
(annotation?,(simpleType?,(minExclusive |minInclusive|
maxExclusive|maxInclusive|totalDigits|fractionDigits|
length|minLength|maxLength|enumeration|whiteSpace|pattern)*)?,
((attribute|attributeGroup)*,anyAttribute?))

Content for complexContent:
(annotation?,(group|all|choice|sequence)?,
((attribute|attributeGroup)*,anyAttribute?))

</restriction>

(? 符号声明在 restriction 元素中该元素可出现零次或一次。)

属性 描述
id 可选。规定该元素的唯一的 ID。
base 必需。规定在该 schema(或由指定的命名空间指示的其他 schema)中定义的内建数据类型、simpleType 或 complexType 元素的名称。
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>

实例 2

本例定义了一个名为 "initials" 的元素。"initials" 元素是带有约束的简单类型。可接受的值是三个从 a 到 z 的大写或小写字母:

<xs:element name="initials">
  <xs:simpleType>
    <xs:restriction base="xs:string">
      <xs:pattern value="[a-zA-Z][a-zA-Z][a-zA-Z]"/>
    </xs:restriction>
  </xs:simpleType>
</xs:element>

实例 3

本例定义了一个名为 "password" 元素。"password" 元素是带有约束的简单类型。值必须为最少 5 个字符且最多 8 个字符:

<xs:element name="password">
  <xs:simpleType>
    <xs:restriction base="xs:string">
      <xs:minLength value="5"/>
      <xs:maxLength value="8"/>
    </xs:restriction>
  </xs:simpleType>
</xs:element>

实例 4

本例展示了一个使用约束的复杂类型定义。复杂类型 "Chinese_customer" 从一个普通的 customer 复杂类型派生而来,其 country 元素的固定值是 "China":

<xs:complexType name="customer">
  <xs:sequence>
    <xs:element name="firstname" type="xs:string"/>
    <xs:element name="lastname" type="xs:string"/>
    <xs:element name="country" type="xs:string"/>
  </xs:sequence>
</xs:complexType>

<xs:complexType name="Norwegian_customer">
  <xs:complexContent>
    <xs:restriction base="customer">
      <xs:sequence>
        <xs:element name="firstname" type="xs:string"/>
        <xs:element name="lastname" type="xs:string"/>
        <xs:element name="country" type="xs:string" fixed="Norway"/>
      </xs:sequence>
    </xs:restriction>
  </xs:complexContent>
</xs:complexType>


XML Schema 参考手册 完整 XML Schema 参考手册
阅读全文
以上是名动网为你收集整理的 XML Schema restriction 元素全部内容。
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。
相关文章
  •  XQuery 函数

    XQuery 函数

    2023-04-23 XQuery教程

    XQuery 函数 在 XQuery 中包含许多内置的函数,本节介绍如何调用或者自定义 XQuery 函数。XQuery 1.0、XPath 2.0 以及 XSLT 2.0 ...

  •  XSLT <xsl:processing-instruction> 元素

    XSLT <xsl:processing-instruction> 元素

    2023-06-16 XSLT教程

    XSLT xsl:processing-instruction 元素XSLTxsl:processing-instruction元素向输出写一条执行指令。 完整的 XSLT 元素参考手册定...

  •  XSLT key() 函数

    XSLT key() 函数

    2023-04-05 XSLT教程

    XSLT key() 函数 完整的 XSLT 函数参考对象定义和用法 key() 函数通过使用由 xsl:key 元素规定的索引号,从文档中返回节点集。语...

  •  DTD 总结

    DTD 总结

    2023-05-01 DTD教程

    您已经学习了 DTD,下一步呢? 到本节为止,我们已经讲解完所有的有关于 DTD 的知识,接下来,你该如何深入学习呢?DTD 总结本教...

  •  XPath 运算符

    XPath 运算符

    2023-05-15 XPath教程

    XPath 运算符 本节为你介绍可以在 XPath 表达式中使用的运算符。XPath 表达式可返回节点集、字符串、逻辑值以及数字。XPath 运算...

© 2024 名动网 mdwl.vip 版权所有 联系我们