Easy Tutorial
❮ El Annotation Schema Complex Elements ❯

XML Schema attribute Element



Definition and Usage

The attribute element defines an attribute.

Element Information

Syntax

(? symbol indicates that the element can appear zero or one time within the attribute element.)

Attribute Description
default Optional. Specifies the default value of the attribute. The default and fixed attributes cannot appear together.
fixed Optional. Specifies a fixed value for the attribute. The default and fixed attributes cannot appear together.
form Optional. Specifies the form of the attribute. The default value is the value of the attributeFormDefault attribute of the schema element containing this attribute. It can be set to the following values: "qualified" - indicates that the attribute must be qualified by a namespace prefix and the NCName of the attribute without a colon. <br>"unqualified" - indicates that the attribute does not need to be qualified by a namespace prefix and does not need to match the NCName of the attribute, i.e., the local name.
id Optional. Specifies a unique ID for the element.
name Optional. Specifies the name of the attribute. The name and ref attributes cannot appear together.
ref Optional. Specifies a reference to a specified attribute. The name and ref attributes cannot appear together. If ref is present, the simpleType element, form, and type cannot be present.
type Optional. Specifies a built-in data type or simple type. The type attribute can only appear if the content does not include a simpleType element.
use Optional. Specifies how the attribute is used. It can be set to the following values: optional - the attribute is optional and can have any value (default). <br>prohibited - the attribute cannot be used. <br>required - the attribute is required.
any attributes Optional. Specifies any other attributes with non-schema namespaces.

Example 1

The above example indicates that the "code" attribute is qualified. The only acceptable values are two letters from uppercase A to Z.

Example 2

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

Example 3

An attribute can have both a default value and a specified fixed value. When no other value is specified, the default value is automatically assigned to the attribute. In the following example, the default value is "EN":

When no other value is specified, the fixed value is automatically assigned to the attribute. However, unlike the default value, if you specify any other value for the attribute, the document will be invalid. In the following example, the fixed value is "EN":

Example 4

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

To make an attribute required:


❮ El Annotation Schema Complex Elements ❯