XML technologies / XML Schema / Controlling namespaces / Troublesome attributes

(Excerpt from “XML Schema” by Eric van der Vlist)

We have seen that W3C XML Schema treats global elements and attributes alike, requiring explicit namespace qualification for both. Reasonable as this seems, with little reason to distinguish them, it differs from the recommendation Namespaces in XML. Global attributes turn out to be unusual but useful.

To understand this, examine the recommendation Namespaces in XML . It distinguishes qualified and unqualified attributes. Only attributes applied to elements from another namespace require qualification; these are also called global. Unqualified attributes belong to their parent’s vocabulary without necessarily belonging to its namespace. They inherit namespace membership without showing it. This relates to default namespaces not applying to attributes: they are unnecessary if attributes belong to the parent’s namespace without them. In practice, most XML vocabularies use unqualified attributes:

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

or:

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

Few would use qualified attributes such as:

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

Few would also use this equivalent, with a default namespace for the element but not its attribute:

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

Unfortunately, W3C XML Schema requires global attributes to be qualified, so they cannot represent the unqualified attributes common in XML vocabularies; our unqualified attribute id cannot be global. In practice, we usually define local attributes within elements or complex types. Reusable unqualified attributes can be defined in a separate imported schema without target namespace, risking collisions when combining schemas using this strategy, or hidden within attribute groups:

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

   

 

 

 

back to top