Stylus Studio XML Editor

Table of contents

Appendices

3.2 Attribute Declarations

Attribute Declarations

Attribute declarations provide for:

  • Local valid of attribute information item values using a simple type definition;

  • Specifying default or fixed values for attribute information items.

NOTE: 
<xs:attribute name="age" type="xs:positiveInteger" use="required"/>

The XML representation of an attribute declaration.

The Attribute Declaration Schema Component[top]

The Attribute Declaration Schema Component

The attribute declaration schema component has the following properties:

[Attribute Declaration]

The [a-name] property must match the local part of the names of attributes being valid.

The value of the attribute must conform to the supplied [a-simple_type_definition].

A non-absent value of the [a-target_namespace] property provides for valid of namespace-qualified attribute information items (which must be explicitly prefixed in the character-level form of XML documents). absent values of [a-target_namespace] valid unqualified (unprefixed) items.

A [a-scope] of global identifies attribute declarations available for use in complex type definitions throughout the schema. Locally scoped declarations are available for use only within the complex type definition identified by the [a-scope] property. This property is absent in the case of declarations within attribute group definitions: their scope will be determined when they are used in the construction of complex type definitions.

[a-value_constraint] reproduces the functions of XML 1.0 default and #FIXED attribute values. default specifies that the attribute is to appear unconditionally in the post-schema-validation infoset, with the supplied value used whenever the attribute is not actually present; fixed indicates that the attribute value if present must equal the supplied constraint value, and if absent receives the supplied value as for default. Note that it is values that are supplied and/or checked, not strings.

See [Annotations] for information on the role of the [a-annotation] property.

NOTE: 

A more complete and formal presentation of the semantics of [a-name], [a-target_namespace] and [a-value_constraint] is provided in conjunction with other aspects of complex type valid (see [Element Locally Valid (Complex Type)].)

[ref-xmlinfo] distinguishes attributes with names such as xmlns or xmlns:xsl from ordinary attributes, identifying them as [namespace attributes]. Accordingly, it is unnecessary and in fact not possible for schemas to contain attribute declarations corresponding to such namespace declarations, see [ Not Allowed]. No means is provided in this specification to supply a default value for a namespace declaration.

XML Representation of Attribute Declaration Schema Components[top]

XML Representation of Attribute Declaration Schema Components

The XML representation for an attribute declaration schema component is an [attribute] element information item. It specifies a simple type definition for an attribute either by reference or explicitly, and may provide default information. The correspondences between the properties of the information item and properties of the component are as follows:

If the [attribute] element information item has [schema] as its parent, the corresponding schema component is as follows:

[The Attribute Declaration Schema Component]

otherwise if the [attribute] element information item has [complexType] or [attributeGroup] as an ancestor and the ref [attribute] is absent, it corresponds to an attribute use with properties as follows (unless use='prohibited', in which case the item corresponds to nothing at all):

[The Attribute Use Schema Component] [The Attribute Declaration Schema Component]

otherwise (the [attribute] element information item has [complexType] or [attributeGroup] as an ancestor and the ref [attribute] is present), it corresponds to an attribute use with properties as follows (unless use='prohibited', in which case the item corresponds to nothing at all):

[The Attribute Use Schema Component]

Attribute declarations can appear at the top level of a schema document, or within complex type definitions, either as complete (local) declarations, or by reference to top-level declarations, or within attribute group definitions. For complete declarations, top-level or local, the type attribute is used when the declaration can use a built-in or pre-declared simple type definition. Otherwise an anonymous [simpleType] is provided inline.

The default when no simple type definition is referenced or provided is the simple ur-type definition, which imposes no constraints at all.

Attribute information items valid by a top-level declaration must be qualified with the [a-target_namespace] of that declaration (if this is absent, the item must be unqualified). Control over whether attribute information items valid by a local declaration must be similarly qualified or not is provided by the form [attribute], whose default is provided by the attributeFormDefault [attribute] on the enclosing [schema], via its determination of [a-target_namespace].

The names for top-level attribute declarations are in their own symbol space. The names of locally-scoped attribute declarations reside in symbol spaces local to the type definition which contains them.

Constraints on XML Representations of Attribute Declarations[top]

Constraints on XML Representations of Attribute Declarations Attribute Declaration Representation OK

In addition to the conditions imposed on [attribute] element information items by the schema for schemas,

  1. default and fixed must not both be present.

  2. If default and use are both present, use must have the actual value optional.

  3. If the item's parent is not [schema], then

    1. One of ref or name must be present, but not both.

    2. If ref is present, then all of [simpleType], form and type must be absent.

  4. type and [simpleType] must not both be present.

  5. The corresponding attribute declaration must satisfy the conditions set out in [Constraints on Attribute Declaration Schema Components].

Attribute Declaration Validation Rules[top]

Attribute Declaration Validation Rules Attribute Locally Valid

For an attribute information item to be locally valid with respect to an attribute declaration

  1. The declaration must not be absent (see [Missing Sub-components] for how this can fail to be the case).

  2. Its [a-simple_type_definition] must not be absent.

  3. The item's normalized value must be locally valid with respect to that [a-simple_type_definition] as per [String Valid].

  4. The item's actual value must match the value of the [a-value_constraint], if it is present and fixed.

Schema-Validity Assessment (Attribute)

The schema-validity assessment of an attribute information item depends on its valid alone.

During valid, associations between element and attribute information items among the [children] and [attributes] on the one hand, and element and attribute declarations on the other, are established as a side-effect. Such declarations are called the context-determined declarations. See [c-ctma] (in [Element Locally Valid (Complex Type)]) for attribute declarations, [c-cdde] (in [Element Sequence Locally Valid (Particle)]) for element declarations.

For an attribute information item's schema-validity to have been assessed

  1. A non-absent attribute declaration must be known for it, namely

    1. A declaration which has been established as its context-determined declaration;

    2. A declaration resolved to by its [local name] and [namespace name] as defined by [QName resolution (Instance)], provided its context-determined declaration is not skip.

  2. Its valid with respect to that declaration must have been evaluated as per [Attribute Locally Valid].

  3. Both [c-a1] and [c-a2] of [Attribute Locally Valid] must be satisfied.

For attributes, there is no difference between assessment and strict assessment, so if the above holds, the attribute information item has been strictly assessed.

Attribute Declaration Information Set Contributions[top]

Attribute Declaration Information Set Contributions Assessment Outcome (Attribute)

If the schema-validity of an attribute information item has been assessed as per [Schema-Validity Assessment (Attribute)], then in the post-schema-validation infoset it has properties as follows:

The nearest ancestor element information item with a [e-schema_information] property.
  1. ifit was strictly assessed

    then

    1. ifit was valid as defined by [Attribute Locally Valid]

      thenvalid;

    2. otherwiseinvalid.

  2. otherwisenotKnown.

  1. ifit was strictly assessed

    thenfull;

  2. otherwisenone.

infoset. See [Attribute Default Value] for the other possible value. Validation Failure (Attribute)

If the local valid, as defined by [Attribute Locally Valid] above, of an attribute information item has been assessed, in the post-schema-validation infoset the item has a property:

  1. ifthe item is not valid

    thena list. Applications wishing to provide information as to the reason(s) for the valid failure are encouraged to record one or more error codes (see [Outcome Tabulations (normative)]) herein.

  2. otherwiseabsent.

Attribute Declaration

If an attribute information item is valid with respect to an attribute declaration as per [Attribute Locally Valid] then in the post-schema-validation infoset the attribute information item may, at processor option, have a property:

An item isomorphic to a component to the declaration component itself. Attribute Validated by Type

If [c-sva] of [Attribute Locally Valid] applies with respect to an attribute information item, in the post-schema-validation infoset the attribute information item has a property:

The normalized value of the item as valid.

Furthermore, the item has one of the following alternative sets of properties:

Either

An item isomorphic to a component to the relevant attribute declaration's [a-simple_type_definition] component. If and only if that type definition has [variety] union, then an item isomorphic to a component to that member of its [st-member_type_definitions] which actually valid the attribute item's [normalized value].

or

simple. The [st-target_namespace] of the type definition. true if the [st-name] of the type definition is absent, otherwise false. The [st-name] of the type definition, if it is not absent. If it is absent, schema processors may, but need not, provide a value unique to the definition.

If the type definition has [variety] union, then calling that member of the [st-member_type_definitions] which actually valid the attribute item's normalized value the actual member type definition, there are three additional properties:

The [st-target_namespace] of the actual member type definition. true if the [st-name] of the actual member type definition is absent, otherwise false. The [st-name] of the actual member type definition, if it is not absent. If it is absent, schema processors may, but need not, provide a value unique to the definition.

The first (item isomorphic to a component) alternative above is provided for applications such as query processors which need access to the full range of details about an item's assessment, for example the type hierarchy; the second, for lighter-weight processors for whom representing the significant parts of the type hierarchy as information items might be a significant burden.

Also, if the declaration has a [a-value_constraint], the item has a property:

The canonical lexical representation of the declaration's [a-value_constraint] value.

If the attribute information item was not strictly assessed, then instead of the values specified above,

  1. The item's [a-schema_normalized_value] property has the initial value of the item as its value;

  2. The [a-type_definition] and [a-member_type_definition] properties, or their alternatives, are based on the Simple Type Definition of the Ur-Type.

Constraints on Attribute Declaration Schema Components[top]

Constraints on Attribute Declaration Schema Components

All attribute declarations (see [Attribute Declarations]) must satisfy the following constraints.

Attribute Declaration Properties Correct
  1. The values of the properties of an attribute declaration must be as described in the property tableau in [The Attribute Declaration Schema Component], modulo the impact of [Missing Sub-components].

  2. if there is a [a-value_constraint], the canonical lexical representation of its value must be valid with respect to the [a-simple_type_definition] as defined in [String Valid].

  3. If the [a-simple_type_definition] is or is derived from ID then there must not be a [a-value_constraint].

xmlns Not Allowed

The [a-name] of an attribute declaration must not match xmlns.

NOTE: 

The [a-name] of an attribute is an NCName, which implicitly prohibits attribute declarations of the form xmlns:*.

xsi: Not Allowed

The [a-target_namespace] of an attribute declaration, whether local or top-level, must not match http://www.w3.org/2001/XMLSchema-instance (unless it is one of the four built-in declarations given in the next section).

NOTE: 

This reinforces the special status of these attributes, so that they not only need not be declared to be allowed in instances, but must not be declared. It also removes any temptation to experiment with supplying global or fixed values for e.g. xsi:type or xsi:nil, which would be seriously misleading, as they would have no effect.

Built-in Attribute Declarations[top]

Built-in Attribute Declarations

There are four attribute declarations present in every schema by definition:

Attribute Declaration for the 'type' attribute [a-name] [a-target_namespace] [The built-in ] [a-scope] [a-value_constraint] [a-annotation] Attribute Declaration for the 'nil' attribute [a-name] [a-target_namespace] [The built-in ] [a-scope] [a-value_constraint] [a-annotation] Attribute Declaration for the 'schemaLocation' attribute [a-name] [a-target_namespace] [An anonymous simple type definition, as follows: ] [a-scope] [a-value_constraint] [a-annotation] Attribute Declaration for the 'noNamespaceSchemaLocation' attribute [a-name] [a-target_namespace] [The built-in ] [a-scope] [a-value_constraint] [a-annotation]