XML Schema attribute Element

The example above indicates that the "code" attribute has a restriction. The only acceptable value is two of the uppercase letters from a to z.

Example 2

To declare an attribute using an existing attribute definition within a complex type, use the ref attribute:

Example 3

Attributes can have either a default value OR a fixed value specified. A default value is automatically assigned to the attribute when no other value is specified. In the following example the default value is "EN":

A fixed value is also automatically assigned to the attribute when no other value is specified. But unlike default values; if you specify another value than the fixed, the document is considered invalid. In the following example the fixed value is "EN":

Example 4

All attributes are optional by default. To explicitly specify that the attribute is optional, use the "use" attribute:

To make an attribute required: