XML technologies / XML Schema / Controlling namespaces / Namespaces and XPath expressions
(Excerpt from “XML Schema” by Eric van der Vlist)
Recall that default namespaces do not apply to XPath expressions and that a prefix must be defined for every namespace used in XPath expressions in declarations of xs:unique, xs:key and xs:keyref.
A prefix declaration is therefore necessary for expressions referencing qualified elements and attributes, even if the target namespace is defined as the default namespace. Also note that attribute refer of xs:keyref is a QName that must carry a prefix. An xs:key/xs:keyref for the authors in the previous example could look like this:
<xs:schema targetNamespace="http://dyomedea.com/ns/library" elementFormDefault="qualified" attributeFormDefault="unqualified" xmlns:lib="http://dyomedea.com/ns/library" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="library">
<xs:complexType>
<xs:sequence>
<xs:element name="book" type="lib:bookType" maxOccurs="unbounded"/>
<xs:element name="author" type="lib:authorType" maxOccurs="unbounded"/>
<xs:element name="characters" type="lib:characterType" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
<xs:key name="author">
<xs:selector xpath="lib:author"/>
<xs:field xpath="@id"/>
</xs:key>
<xs:keyref name="keyref" refer="lib:author">
<xs:selector xpath="lib:book/lib:author-ref"/>
<xs:field xpath="@ref"/>
</xs:keyref>
</xs:element>
</xs:schema>
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
back to top