W3C home > Mailing lists > Public > xmlschema-dev@w3.org > May 2001

Re: Where can I find examples of XML Schemas?

From: Eddie Robertsson <eddie@allette.com.au>
Date: Thu, 31 May 2001 09:47:45 +1000
Message-ID: <3B1586A1.D374210C@allette.com.au>
To: Roman Rytov <roman@davinci.co.il>
CC: "'xmlschema-dev@w3.org'" <xmlschema-dev@w3.org>
Hi Roman,

> I tryed to implement UNIQUE element to restrict a set but couldn't do
> it. Where can I find examples of XSD files?

Here is an example schema I developed for a sport tournament (At the end
you'll find the declaration of the Tournament element along with keys,
keyrefs and unique elements). Hope this helps. For more information have
a look in the Primer [1]

Cheers,
/Eddie

[1] http://www.w3.org/TR/xmlschema-0/#specifyingUniqueness
---------------------------------------------------------------------------------------------

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
 <xsd:complexType name="Tournament">
  <xsd:sequence>
   <xsd:element name="Name" type="xsd:string"/>
   <xsd:element name="Type">
    <xsd:simpleType>
     <xsd:restriction base="xsd:string">
      <xsd:enumeration value="Singles"/>
      <xsd:enumeration value="Doubles"/>
     </xsd:restriction>
    </xsd:simpleType>
   </xsd:element>
   <xsd:element name="Date" type="xsd:date"/>
   <xsd:element name="Participants" type="Participants" minOccurs="0"/>
   <xsd:element name="Teams" type="Teams"/>
   <xsd:element name="Matches" type="Matches"/>
  </xsd:sequence>
 </xsd:complexType>
 <xsd:complexType name="Participants">
  <xsd:sequence>
   <xsd:element name="Name" minOccurs="2" maxOccurs="unbounded">
    <xsd:complexType>
     <xsd:simpleContent>
      <xsd:extension base="xsd:string">
       <xsd:attribute name="id" type="xsd:string" use="required"/>
      </xsd:extension>
     </xsd:simpleContent>
    </xsd:complexType>
   </xsd:element>
  </xsd:sequence>
  <xsd:attribute name="nbrParticipants" type="xsd:positiveInteger"
use="required"/>
 </xsd:complexType>
 <xsd:complexType name="Teams">
  <xsd:sequence>
   <xsd:element name="Team" minOccurs="2" maxOccurs="unbounded">
    <xsd:complexType>
     <xsd:sequence>
      <xsd:element name="Member" type="xsd:string" maxOccurs="2"/>
     </xsd:sequence>
     <xsd:attribute name="id" type="xsd:string" use="required"/>
     <xsd:attribute name="Name" type="xsd:string"/>
    </xsd:complexType>
   </xsd:element>
  </xsd:sequence>
  <xsd:attribute name="nbrTeams" type="xsd:positiveInteger"
use="required"/>
 </xsd:complexType>
 <xsd:complexType name="Matches">
  <xsd:sequence>
   <xsd:element name="Match" maxOccurs="unbounded">
    <xsd:complexType>
     <xsd:sequence>
      <xsd:element name="Team" type="xsd:string" minOccurs="2"
maxOccurs="2"/>
     </xsd:sequence>
     <xsd:attribute name="id" type="xsd:string" use="required"/>
    </xsd:complexType>
   </xsd:element>
  </xsd:sequence>
  <xsd:attribute name="nbrMatches" type="xsd:positiveInteger"
use="required"/>
 </xsd:complexType>
 <xsd:element name="Tournament" type="Tournament">
  <xsd:key name="key_Participant">
   <!-- Make sure that each Participant has a unique id -->
   <xsd:selector xpath="Participants/Participant"/>
   <xsd:field xpath="@id"/>
  </xsd:key>
  <xsd:keyref name="ref_Participant" refer="key_Participant">
   <!-- Make sure that the value of each Member element in the Team
elements is an identifier for an existing Participant -->
   <xsd:selector xpath="Teams/Team/Member"/>
   <xsd:field xpath="."/>
  </xsd:keyref>
  <xsd:key name="key_Team">
   <!-- Make sure that each Team has a unique id -->
   <xsd:selector xpath="Teams/Team"/>
   <xsd:field xpath="@id"/>
  </xsd:key>
  <xsd:keyref name="ref_Team" refer="key_Team">
   <!-- Make sure that the value of each Team element in the Match
elements is an identifier for an existing Team -->
   <xsd:selector xpath="Matches/Match/Team"/>
   <xsd:field xpath="."/>
  </xsd:keyref>
  <xsd:unique name="unique_Match">
   <!-- Make sure that each Match has a unique id -->
   <xsd:selector xpath="Matches/Match"/>
   <xsd:field xpath="@id"/>
  </xsd:unique>
 </xsd:element>
</xsd:schema>
Received on Wednesday, 30 May 2001 19:49:15 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Tuesday, 11 January 2011 00:14:21 GMT