Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

XML Schema attribute Element

XML Schema attribute Element


XML Schema Reference Manual Complete XML Schema Reference Manual


Definition and Usage

The attribute element defines an attribute.

Element Information

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.)

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

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:

  • "qualified" - indicates that the attribute must be qualified by a namespace prefix and the attribute's no-colon name (NCName).
  • "unqualified" - indicates that the attribute does not need to be qualified by a namespace prefix, nor does it need to match the attribute's no-colon name (NCName), that is, 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 both be present. | | ref | Optional. Specifies a reference to a specified attribute. The name and ref attributes cannot both be present. If ref is present, the simpleType element, form, and type cannot be present. | | type | Optional. Specifies a built-in data type or a simple type. The type attribute can only be present if the content does not contain a simpleType element. | | use |

    Optional. Specifies how the attribute should be used. Can be set to the following values:

    | | *any attributes* | Optional. Specifies any other attributes with a non-schema namespace. |

    Example 1

    xs:simpleType

      

        

      

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

    Example 2

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

      xs:simpleType

        

          

        

      

      

    Example 3

    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":

    Example 4

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

    Making an attribute required:


    XML Schema Reference Manual Complete XML Schema Reference Manual