Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

XML Schema restriction Element

XML Schema restriction Element


XML Schema Reference Manual Complete XML Schema Reference Manual


Definition and Usage

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

Element Information

Syntax

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

(The ? symbol declares that within the restriction element, the element can appear zero or one time.)

property Description
id Optional. Specifies a unique ID for the element.
base Required. Specifies the name of a built-in data type, simpleType, or complexType element defined in this schema (or in another schema indicated by the specified namespace).
any attributes Optional. Specifies any other attributes with a non-schema namespace.

Example 1

The following example defines an element named "age" with a constraint. The value of age cannot be less than 0 or greater than 100:

  xs:simpleType

    

      

      

    

  

Example 2

This example defines an element named "initials". The "initials" element is a simple type with a constraint. The acceptable value is three uppercase or lowercase letters from a to z:

  xs:simpleType

    

      

    

  

Example 3

This example defines an element named "password". The "password" element is a simple type with a constraint. The value must be a minimum of 5 characters and a maximum of 8 characters:

  xs:simpleType

    

      

      

    

  

Example 4

This example shows a complex type definition using a restriction. The complex type "Chinese_customer" is derived from a normal customer complex type, and the fixed value of its country element is "China":

  xs:sequence

    

    

    

  

  xs:complexContent

    

      xs:sequence

        

        

        

      

    

  


XML Schema Reference Manual Complete XML Schema Reference Manual