15.2.48. XML Schema restriction element

发布时间 :2025-10-25 12:23:26 UTC      

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

Definition and usage

The restriction element defines constraints on simpleType, simpleContent, or complexContent definitions.

Element information

  • 父元素: SimpleType, simpleContent, complexContent

Grammar

<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>

(? The symbol declares that the element can appear zero or once in the restriction element. )

Attribute

Description

Id

Optional. Specifies the unique ID of the element.

Base

Necessary. Specifies the name of the built-in data type, simpleType, or complexType element defined in the schema (or other schema indicated by the specified namespace).

Any attributes

Optional. Specifies any other attributes with the non-schema namespace.

Example 1

The following example defines an element named “age” 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>

Example 2

This example defines an element named “initials”. The “initials” element is a simple type with constraints. Acceptable values are three uppercase or lowercase letters from a to 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>

Example 3

This example defines an element named “password”. The “password” element is a simple type with constraints. The value must be at least 5 characters and up to 8 characters:

<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>

Example 4

This example shows a complex type definition that uses constraints. The complex type “Chinese_customer” is derived from a normal customer complex type, and the fixed value of its country element is “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 参考手册

Principles, Technologies, and Methods of Geographic Information Systems  102

In recent years, Geographic Information Systems (GIS) have undergone rapid development in both theoretical and practical dimensions. GIS has been widely applied for modeling and decision-making support across various fields such as urban management, regional planning, and environmental remediation, establishing geographic information as a vital component of the information era. The introduction of the “Digital Earth” concept has further accelerated the advancement of GIS, which serves as its technical foundation. Concurrently, scholars have been dedicated to theoretical research in areas like spatial cognition, spatial data uncertainty, and the formalization of spatial relationships. This reflects the dual nature of GIS as both an applied technology and an academic discipline, with the two aspects forming a mutually reinforcing cycle of progress.