15.2.8. XSD qualification / Facets

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

Restriction is used to define acceptable values for XML elements or attributes. The qualification of the XML element is called facet.

Limitation of value

The following example defines an element with a qualifier named “age”. The value of age cannot be less than 0 or higher than 120:

<xs:element name="age">
  <xs:simpleType>
    <xs:restriction base="xs:integer">
      <xs:minInclusive value="0"/>
      <xs:maxInclusive value="120"/>
    </xs:restriction>
  </xs:simpleType>
</xs:element>

The qualification of a set of values.

To limit the content of the XML element to a set of acceptable values, we use an enumeration constraint (enumeration constraint).

The following example defines an element with a qualified name “car”. The only acceptable values are Audi, Golf, BMW:

<xs:element name="car">
  <xs:simpleType>
    <xs:restriction base="xs:string">
      <xs:enumeration value="Audi"/>
      <xs:enumeration value="Golf"/>
      <xs:enumeration value="BMW"/>
    </xs:restriction>
  </xs:simpleType>
</xs:element>

The above example can also be written as:

<xs:element name="car" type="carType"/>
<xs:simpleType name="carType">
  <xs:restriction base="xs:string">
    <xs:enumeration value="Audi"/>
    <xs:enumeration value="Golf"/>
    <xs:enumeration value="BMW"/>
  </xs:restriction>
</xs:simpleType>

注意: In this case, the type “carType” can be used by other elements because it is not part of the “car” element.

The limitation of a series of values.

To define the content limit of a XML element as a series of numbers or letters that can be used, we use a schema constraint (pattern constraint).

The following example defines an element with a qualified name “letter”. Acceptable values are only one of the lowercase letters a-z:

<xs:element name="letter">
  <xs:simpleType>
    <xs:restriction base="xs:string">
      <xs:pattern value="[a-z]"/>
    </xs:restriction>
  </xs:simpleType>
</xs:element>

The next example defines an element with a qualified name “initials”. Acceptable values are three of the uppercase letters A-Z:

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

The next example also defines an element with a qualified name “initials”. The acceptable values are three of the uppercase or lowercase letters 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>

The next example defines an element with a qualified name “choice. Acceptable values are one of the letters x, y, or z:

<xs:element name="choice">
  <xs:simpleType>
    <xs:restriction base="xs:string">
      <xs:pattern value="[xyz]"/>
    </xs:restriction>
  </xs:simpleType>
</xs:element>

The next example defines an element with a qualified name “prodid”. The acceptable value is a sequence of five Arabic numerals with a range of 0-9 for each number:

<xs:element name="prodid">
  <xs:simpleType>
    <xs:restriction base="xs:integer">
      <xs:pattern value="[0-9][0-9][0-9][0-9][0-9]"/>
    </xs:restriction>
  </xs:simpleType>
</xs:element>

Other restrictions on a series of values

The following example defines an element with a qualified name “letter”. Acceptable values are zero or more letters in a-z:

<xs:element name="letter">
  <xs:simpleType>
    <xs:restriction base="xs:string">
      <xs:pattern value="([a-z])*"/>
    </xs:restriction>
  </xs:simpleType>
</xs:element>

The following example defines an element with a qualified name “letter”. Acceptable values are one or more pairs of letters, each consisting of a lowercase letter followed by an uppercase letter. For example, “sToP” will pass the validation of this pattern, but “Stop”, “STOP” or “stop” will not:

<xs:element name="letter">
  <xs:simpleType>
    <xs:restriction base="xs:string">
      <xs:pattern value="([a-z][A-Z])+"/>
    </xs:restriction>
  </xs:simpleType>
</xs:element>

The following example defines an element with a qualified name “gender”. Acceptable values are male or female:

<xs:element name="gender">
  <xs:simpleType>
    <xs:restriction base="xs:string">
      <xs:pattern value="male|female"/>
    </xs:restriction>
  </xs:simpleType>
</xs:element>

The following example defines an element with a qualified name “password”. Acceptable values are a line of 8 characters that must be uppercase or lowercase letters a-z or the number 0-9:

<xs:element name="password">
  <xs:simpleType>
    <xs:restriction base="xs:string">
      <xs:pattern value="[a-zA-Z0-9]{8}"/>
    </xs:restriction>
  </xs:simpleType>
</xs:element>

The limitation of white space characters

To specify how white space characters (whitespace characters) are handled, we need to use whiteSpace qualification.

The following example defines an element with a qualified name “address”. This whiteSpace qualification is set to “preserve”, which means that the XML processor does not remove any white space characters:

<xs:element name="address">
  <xs:simpleType>
    <xs:restriction base="xs:string">
      <xs:whiteSpace value="preserve"/>
    </xs:restriction>
  </xs:simpleType>
</xs:element>

This example also defines an element with a qualified name “address”. This whiteSpace qualification is set to “replace”, which means that the XML processor removes all white space characters (line feeds, carriage returns, spaces, and tabs):

<xs:element name="address">
  <xs:simpleType>
    <xs:restriction base="xs:string">
      <xs:whiteSpace value="replace"/>
    </xs:restriction>
  </xs:simpleType>
</xs:element>

This example also defines an element with a qualified name “address”. This whiteSpace qualification is set to “collapse”, which means that the XML processor will remove all white space characters (line feeds, carriage returns, spaces, and tabs will be replaced with spaces, spaces at the beginning and end will be removed, and multiple consecutive spaces will be reduced to a single space):

<xs:element name="address">
  <xs:simpleType>
    <xs:restriction base="xs:string">
      <xs:whiteSpace value="collapse"/>
    </xs:restriction>
  </xs:simpleType>
</xs:element>

The limitation of length

To limit the length of the value in an element, we need to use length, maxLength, and minLength to qualify.

This example defines an element with a qualifier named “password”. The value must be accurate to 8 characters:

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

This example also defines an element with a qualified name “password”. The minimum value is 5 characters and the maximum is 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>

Qualification of data type

Limit

Description

Enumeration

Define a list of acceptable values

FractionDigits

Defines the maximum number of decimal places allowed. Must be greater than or equal to 0.

Length

Defines the exact number of characters or list items allowed. Must be greater than or equal to 0.

MaxExclusive

Defines the upper limit of the value. The allowed value must be less than this value.

MaxInclusive

Defines the upper limit of the value. The allowed value must be less than or equal to this value.

MaxLength

Defines the maximum number of characters or list items allowed. Must be greater than or equal to 0.

MinExclusive

Defines the lower limit of the value. The allowed value must be greater than this value.

MinInclusive

Defines the lower limit of the value. The allowed value must be greater than or equal to this value.

MinLength

Defines the minimum number of characters or list items allowed. Must be greater than or equal to 0.

Pattern

Defines a precise sequence of acceptable characters.

TotalDigits

Defines the exact number of digits allowed for Arabic numerals. Must be greater than 0.

WhiteSpace

Defines how white space characters (line feeds, carriage returns, spaces, and tabs) are handled.

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.