9. Defining Uniqueness, Keys and Key References (samples)
Sample 1
<book identifier="isbn-0836217462">
<isbn>
0836217462
</isbn>
<title>
Being a Dog Is a Full-Time Job
</title>
<author-ref ref="au-Charles_M._Schulz"/>
<character-refs>
ch-Peppermint_Patty ch-Snoopy ch-Schroeder ch-Lucy
</character-refs>
</book>
Sample 2
<xs:element name="book">
<xs:complexType>
<xs:sequence>
<xs:element name="isbn" type="xs:int"/>
<xs:element name="title" type="xs:string"/>
<xs:element name="author-ref">
<xs:complexType>
<xs:attribute name="ref" type="xs:IDREF" use="required"/>
</xs:complexType>
</xs:element>
<xs:element name="character-refs" type="xs:IDREFS"/>
</xs:sequence>
<xs:attribute name="identifier" type="xs:ID" use="required"/>
</xs:complexType>
</xs:element>
Sample 3
<xs:element name="book" maxOccurs="unbounded">
<xs:complexType>
.../...
</xs:complexType>
<xs:unique name="book">
.../...
</xs:unique>
</xs:element>
Sample 4
<xs:element name="book" maxOccurs="unbounded">
<xs:complexType>
.../...
</xs:complexType>
<xs:unique name="book">
<xs:selector xpath="book"/>
.../...
</xs:unique>
</xs:element>
Sample 5
<xs:element name="book" maxOccurs="unbounded">
<xs:complexType>
.../...
</xs:complexType>
<xs:unique name="book">
<xs:selector xpath="book"/>
<xs:field xpath="isbn"/>
</xs:unique>
</xs:element>
Sample 6
<xs:element name="library">
<xs:complexType>
.../...
</xs:complexType>
<xs:unique name="author">
<xs:selector xpath="author"/>
<xs:field xpath="first-name"/>
<xs:field xpath="middle-name"/>
<xs:field xpath="last-name"/>
</xs:unique>
</xs:element>
Sample 7
<xs:element name="library">
<xs:complexType>
.../...
</xs:complexType>
<xs:key name="book">
<xs:selector xpath="book"/>
<xs:field xpath="isbn"/>
</xs:key>
</xs:element>
Sample 8
<library>
<books>
<book>
.../...
<author-ref ref="Charles M. Schulz"/>
.../...
</book>
.../...
</books>
<authors>
<author>
<name>
Charles M. Schulz
</name>
.../...
</author>
.../...
</authors>
</library>
Sample 9
<library>
<books>
<book>
.../...
<author-ref ref="Charles M. Schulz"/>
.../...
</book>
.../...
</books>
<authors>
<category id="comics">
<author>
<name>
Charles M. Schulz
</name>
.../...
</author>
.../...
</category>
<category id="novels">
.../...
</category>
.../...
</authors>
</library>
Sample 11
xpath="author|character"
Sample 12
xpath="lib:author"
Sample 15
xpath="authors/author"
Sample 16
xpath=".//author"
Sample 17
xpath="author/@id"
Sample 18
xpath="@id|@name"
Sample 19
xpath="/library/author"
Sample 20
xpath="../author"
Sample 21
xpath=".//*[@id]"
Sample 22
xpath="author[@type='comics']"
Sample 23
xpath="substring-after(@xlink:href, '#')"
Sample 24
xpath="//author"
Sample 25
<library xsi:noNamespaceSchemaLocation="library-keys-id-key.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<book id="isbn-0836217462">
<isbn>
0836217462
</isbn>
<title>
Being a Dog Is a Full-Time Job
</title>
<author-ref ref="au-Charles_M._Schulz"/>
<character-ref ref="ch-Peppermint_Patty"/>
<character-ref ref="ch-Snoopy"/>
<character-ref ref="ch-Schroeder"/>
<character-ref ref="ch-Lucy"/>
</book>
.../...
<author id="au-Charles_M._Schulz">
<name>
Charles M. Schulz
</name>
<nickName>
SPARKY
</nickName>
<born>
November 26, 1922
</born>
<dead>
February 12, 2000
</dead>
</author>
<character id="ch-Peppermint_Patty">
<name>
Peppermint Patty
</name>
<since>
Aug. 22, 1966
</since>
<qualification>
bold, brash and tomboyish
</qualification>
</character>
...
</library>
Sample 26
<xs:element name="library">
<xs:complexType>
.../...
</xs:complexType>
<xs:key name="ID">
<xs:selector xpath="book|author|character"/>
<xs:field xpath="@id"/>
</xs:key>
<xs:keyref name="IDREF" refer="ID">
<xs:selector xpath="book/author-ref|book/character-ref"/>
<xs:field xpath="@ref"/>
</xs:keyref>
</xs:element>
Sample 27
<book id="b0836217462" available="true">
<isbn>
0836217462
</isbn>
<title lang="en">
Being a Dog Is a Full-Time Job
</title>
../..
</book>
Sample 28
<book id="b0836217462" available="true" isbn="0836217462"
title="Beinga Dog Is a Full-Time Job">
.../...
</book>
Sample 29
<xs:complexType>
<xs:sequence>
<xs:element ref="isbn" minOccurs="0"/>
<xs:element ref="title" minOccurs="0"/>
<xs:element ref="author" minOccurs="0" maxOccurs="unbounded"/>
<xs:element ref="character" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
<xs:attribute ref="id"/>
<xs:attribute ref="available"/>
<xs:attribute ref="isbn"/>
<xs:attribute ref="title"/>
</xs:complexType>
Sample 30
<xs:key name="isbn">
<xs:selector xpath="."/>
<xs:field xpath="isbn|@isbn"/>
</xs:key>
<xs:key name="title">
<xs:selector xpath="."/>
<xs:field xpath="title|@title"/>
</xs:key>
Sample 31
<xs:element name="book">
<xs:complexType>
<xs:sequence>
<xs:element ref="isbn" minOccurs="0"/>
<xs:element ref="title" minOccurs="0"/>
<xs:element ref="author" minOccurs="0" maxOccurs="unbounded"/>
<xs:element ref="character" minOccurs="0"
maxOccurs="unbounded"/>
</xs:sequence>
<xs:attribute ref="id"/>
<xs:attribute ref="available"/>
<xs:attribute ref="isbn"/>
<xs:attribute ref="title"/>
</xs:complexType>
<xs:key name="isbn">
<xs:selector xpath="."/>
<xs:field xpath="isbn|@isbn"/>
</xs:key>
<xs:key name="title">
<xs:selector xpath="."/>
<xs:field xpath="title|@title"/>
</xs:key>
</xs:element>