Schema El Attribute
* * Complete XML Schema Reference](#)
* * *
## 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
(annotation?,(simpleType?))
(The ? symbol indicates that the element can occur zero or one time within the `attribute` element.)
| Attribute | Description |
| --- | --- |
| default | Optional. Specifies the default value for the attribute. The `default` and `fixed` attributes cannot both be present. |
| fixed | Optional. Specifies a fixed value for the attribute. The `default` and `fixed` attributes cannot both be present. |
| 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. Can be set to one of the following values: * "qualified" - Indicates that this attribute must be qualified with a namespace prefix and its NCName (No-Colon Name). * "unqualified" - Indicates that this attribute does not need to be qualified with a namespace prefix and does not need to match its NCName (i.e., local name). |
| id | Optional. Specifies a unique ID for this element. |
| name | Optional. Specifies the name of the attribute. The `name` and `ref` attributes cannot both be present. |
| ref | Optional. Specifies a reference to a specified attribute. The `name` and `ref` attributes cannot both be present. If `ref` appears, the `simpleType` element, `form`, and `type` cannot appear. |
| type | Optional. Specifies a built-in data type or a simple type. The `type` attribute can only appear when the content does not contain a `simpleType` element. |
| use | Optional. Specifies how the attribute is used. Can be set to one of the following values: * optional - The attribute is optional and can have any value (default). * prohibited - The attribute cannot be used. * required - The attribute is required. |
| _any attributes_ | Optional. Specifies any other attributes with a non-schema namespace. |
### Example 1
The example above indicates that the "code" attribute has a constraint. The only acceptable values are two 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
An attribute can have either a default value or a specified fixed value. If no other value is specified, the default value is automatically assigned to the attribute. In the example below, the default value is "EN":
If no other value is specified, the fixed value is automatically assigned to the attribute. However, unlike the default value, if you specify a value other than the fixed value for the attribute, the document will be validated as invalid. In the example below, 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:
* * Complete XML Schema Reference](#)
YouTip