xs:attribute

Purpose

This element defines an attribute.

The name attribute and the ref attribute are mutually exclusive.

If the xs:attribute element is the child element of an xs:schema element, it defines a global attribute and the name attribute is required.

If the xs:attribute element is the descendant element of an xs:complexType element, its name attribute defines local attributes.

Parent element xs:attributeGroup, xs:complexType, xs:extension or xs:schema
Child elements xs:annotation, xs:simpleType
Attributes default, fixed, form, name, ref, type, use
Attributes
Name Type Description
default xs:string

This attribute enables you to specify a default value for an attribute definition. The default value is used if the attribute is not explicitly specified in the XML instance.

Notes:

  1. The default attribute may not be used together with the fixed attribute.
  2. Specifying a default value for an attribute only makes sense if the attribute itself is optional.
fixed xs:string

This attribute specifies a fixed value for the attribute. That value cannot be changed later on (i.e. it is a constant value). This has the following consequences for instances of that schema:

  • Attribute not present in instance:
    Tamino inserts the attribute with the value specified by the fixed attribute.

  • Attribute present in instance:
    The value of the attribute must match the value specified by the fixed attribute.

Note:
The fixed attribute may not be used together with the default attribute.

form xs:NMTOKEN

This attribute specifies whether the appearance of locally-declared attributes in an instance document must be qualified with a namespace prefix. It overrides the default that is set using the attributeFormDefault attribute of the xs:schema element. It can have either the value "qualified" or "unqualified" (default value).

name xs:NCName

This attribute specifies a name for the attribute to be defined using the xs:attribute element.

ref xs:QName A global attribute can be referenced in other declarations in the same schema using the ref attribute of the xs:attribute element. The value of the ref attribute must refer to a global attribute. If you specify a ref attribute, you cannot specify a name attribute on that attribute declaration.
type xs:QName

This attribute indicates the type of the attribute to be defined using the xs:attribute element. It may not be specified if there is a xs:simpleType present, as the occurrence of the type attribute is mutually exclusive with the occurrence of xs:simpleType.

The type can be any of the predefined types described in section 3 "Built-in datatypes" of W3C Recommendation, XML Schema Part 2: Datatypes or any user-defined simple type.

use xs:NMTOKEN

The use attribute determines the multiplicity of attributes. It may have one of the following values:

required

The attribute must appear once.

optional

The attribute may appear once.

prohibited

The attribute must not appear at all.

The default value for the use attribute is "optional".

Restriction:

If the default attribute has been specified in an attribute definition, the use attribute may only be specified with the value "optional".

Example

This example shows an attribute definition using restriction. It defines a simple type that can only accept the values:

instrumentalist
jazzSinger
jazzComposer

<xs:attribute name = "type">
  <xs:simpleType>
    <xs:restriction base = "xs:NMTOKEN">
      <xs:enumeration value = "instrumentalist"/>
      <xs:enumeration value = "jazzSinger"/>
      <xs:enumeration value = "jazzComposer"/>
    </xs:restriction>
  </xs:simpleType>
</xs:attribute>

The next example presents a more complex attribute definition in TSD .

<xs:attribute name = "C_ob_id" type = "xs:integer">
  <xs:annotation>
    <xs:appinfo>
      <tsd:attributeInfo>
        <tsd:physical>
          <tsd:native>
            <tsd:objectRef>
              <tsd:collectionRef>Customers</tsd:collectionRef>
              <tsd:accessPredicate operator = "=">
                <tsd:nodeRef>/Customer/CustomerNo</tsd:nodeRef>
              </tsd:accessPredicate>
            </tsd:objectRef>
          </tsd:native>
        </tsd:physical>
      </tsd:attributeInfo>
    </xs:appinfo>
  </xs:annotation>
</xs:attribute>