home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  

Book HomeXML SchemaSearch this book

10.4. Disruptive Attributes

So far we have seen that W3C XML Schema treats global attributes and elements alike, requiring both types to be explicitly namespace-qualified to be global. Although this approach makes sense--there's little reason to treat elements and attributes differently--it's different from the approach the Namespaces in XML Recommendation took. Global attributes turn out to be a rather unusual, though useful, case.

To understand this phenomenon, we need to examine the Namespaces in XML Recommendation closely. This differentiates qualified and unqualified attributes, explaining that only attributes applied to elements from another namespace need to be qualified (these are also called global attributes), and that unqualified attributes are considered to belong to the vocabulary from their parent element without needing to belong to their namespace. In this case, they inherit the membership to the namespace of their parent element without needing to show it. This is tightly linked to the fact that default namespaces do not apply to attributes (they don't need to since attributes are considered members of the namespace of their parent without needing default namespaces). In practice, most XML vocabularies will use unqualified attributes, such as:

<book id="b0836217462" xmlns="http://dyomedea.com/ns/library"/>


<lib:book id="b0836217462"

Very few would use qualified attributes, such as:

<lib:book lib:id="b0836217462"

Also, very few would use that or its equivalent if we use a default namespace for the element that doesn't apply to the attribute:

<book lib:id="b0836217462" xmlns="http://dyomedea.com/ns/library"

Unfortunately, since the W3C XML Schema requires that all the global attributes be qualified, this means that global attributes can't be used for those unqualified attributes that are used most of the time in XML vocabularies, and that our unqualified id attribute cannot be declared as global. In practice, this means that most of the time we will just define local attributes within the element or complex type definitions. When we want to define unqualified attributes that may be reused in different elements, we will either define them in a specific schema without a target namespace, which will be imported (but there is risk of collision if we mix several schemas for different target namespaces following this policy), or "hide" those attributes inside of attribute groups, such as:

<xs:attributeGroup name="id">
  <xs:attribute name="id" form="unqualified" type="xs:ID"/>

Library Navigation Links

Copyright © 2002 O'Reilly & Associates. All rights reserved.