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

Book HomeXML SchemaSearch this book

10.5. Namespaces and XPath Expressions

It's time to remember that default namespaces do not apply to XPath expressions, and that a prefix needs to be defined for each namespace used in the XPath expressions of the xs:unique, xs:key, and xs:keyref declarations!

A prefix declaration is therefore required to write expressions that reference qualified elements and attributes, even if the target namespace is defined as the default namespace. It's also important to notice that the xs:keyref refer attribute is a QName that needs to be prefixed, and a xs:key/xs:keyref on the authors in (in our previous example) with a namespace could become:

<xs:schema targetNamespace="http://dyomedea.com/ns/library"
  elementFormDefault="qualified" attributeFormDefault="unqualified"
  <xs:element name="library">
        <xs:element name="book" type="lib:bookType"
        <xs:element name="author" type="lib:authorType"
        <xs:element name="characters" type="lib:characterType"
    <xs:key name="author">
      <xs:selector xpath="lib:author"/>
      <xs:field xpath="@id"/>
    <xs:keyref name="keyref" refer="lib:author">
      <xs:selector xpath="lib:book/lib:author-ref"/>
      <xs:field xpath="@ref"/>

Library Navigation Links

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