El Restriction
* * Complete XML Schema Reference](#)
* * *
## Definition and Usage
The restriction element defines constraints on a simpleType, simpleContent, or complexContent definition.
### Element Information
* **Parent Elements:** simpleType, simpleContent, complexContent
### Syntax
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 the element can appear zero or one time within the restriction element.)
| Attribute | 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 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 constraints. The value of age cannot be less than 0 or greater than 100:
### 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:
### 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 at most 8 characters:
### Example 4
This example shows a complex type definition using constraints. The complex type "Chinese_customer" is derived from a regular customer complex type, with its country element having a fixed value of "China":
* * Complete XML Schema Reference](#)
YouTip