XML technologies / XML Schema / XML Schema element reference / xs:attribute (global definition)
(Excerpt from “XML Schema” by Eric van der Vlist)
Global attribute definition referenceable within the same schema or from others.
<xs:attribute
default = xs:string
fixed = xs:string
id = xs:ID
name = xs:NCName
type = xs:QName
{beliebige Attribute mit einem Nicht-Schema-Namensraum}
>
Content: (xs:annotation?, xs:simpleType?)
</xs:attribute>May occur within: xs:schema
Description
Attributes defined at schema top level, using an xs:attribute directly under document element xs:schema, are global.
Global attributes have global scope: their qualified names can be referenced anywhere in this schema or schemas importing or including it.
Attributes are identified by qualified name, but attribute name expects the local name.
Definition assigns a simple type to the element, either by reference through a type attribute naming a simple type by qualified name, or inline by embedding the simple-type definition, element xs:simpleType, in element xs:attribute.
Restrictions
If a target namespace exists, global attributes must be qualified, carrying a prefix in instance documents. Most vocabularies use unprefixed attributes except foreign attributes on elements of other namespaces, so global attributes are rarely used with target namespaces. Attribute groups (xs:attributeGroup) can encapsulate unqualified definitions reusable in several complex types.
Qualified-name identification prevents defining several global attributes with the same qualified name. If a schema needs several definitions with the same name but different data types, all except one must be local. Simple types or attribute groups can then define reusable content models instead of global attributes.
All global attributes must belong to the target namespace if one is defined. Without a target namespace, all global and local attributes must be unqualified.
Example
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:attribute name="id" type="xs:ID"/>
<xs:attribute name="available" type="xs:boolean"/>
<xs:attribute name="lang" type="xs:language"/>
.../...
</xs:schema>Attributes
default
Default value. If present, the processor adds a missing attribute with this value. Attributes default and fixed are mutually exclusive.
fixed
If present, the value is fixed and must equal this value. Attributes default and fixed are mutually exclusive.
id
Element ID according to W3C XML Schema.
name
Attribute’s local name, without namespace prefix.
type
Qualified name of a simple type; omit if a simple-type definition is embedded.
Copyright © 2003 O'Reilly Verlag GmbH & Co. KG
You may print the online version for your private use.
Otherwise, this chapter from “XML Schema” is subject to the same conditions as the bound edition. The work, including all its parts, is protected by copyright. All rights reserved, including reproduction, translation, microfilming, and storage and processing in electronic systems.
O’Reilly Verlag GmbH & Co. KG, Balthasarstraße 81, 50670 Köln, kommentar(at)oreilly.de