XML Schema attribute Element
Complete XML Schema Reference Manual
Definition and Usage
The attribute element defines an attribute.
Element Information
- Parent elements: attributeGroup, schema, complexType, restriction (both simpleContent and complexContent), extension (both simpleContent and complexContent)
Syntax
default=string fixed=string form=qualified|unqualified id=ID name=NCName ref=QName type=QName use=optional|prohibited|required any attributes (annotation?,(simpleType?)) (The ? symbol declares that the element can occur zero or one time in the attribute element.) Optional. Specifies the form of the attribute. The default value is the value of the attributeFormDefault attribute of the schema element that contains this attribute. Can be set to the following values: Optional. Specifies how the attribute should be used. Can be set to the following values: The example above indicates that the "code" attribute has a restriction. The only acceptable values are two uppercase letters from A to Z. To declare an attribute using an existing attribute definition in a complex type, use the ref attribute: An attribute can have either a default value or a specified fixed value. When no other value is specified, the default value is automatically assigned to the attribute. In the example below, the default value is "EN": When no other value is specified, the fixed value is automatically assigned to the attribute. But unlike the default value, if you specify a value other than the fixed value for the attribute, the document will fail validation. In the example below, the fixed value is "EN": All attributes are optional by default. To explicitly specify that an attribute is optional, use the "use" attribute: Making an attribute required:
property
Description
default
Optional. Specifies the default value of the attribute. The default and fixed attributes cannot both be present.
fixed
Optional. Specifies the fixed value of the attribute. The default and fixed attributes cannot both be present.
form
| | *any attributes* | Optional. Specifies any other attributes with a non-schema namespace. |
Example 1
Example 2
Example 3
Example 4
Complete XML Schema Reference Manual