W3C home > Mailing lists > Public > xmlschema-dev@w3.org > July 2004

Re: More Key/Keyref Questions

From: George Cristian Bina <george@sync.ro>
Date: Fri, 30 Jul 2004 11:26:52 +0300
Message-ID: <410A064C.3000609@sync.ro>
To: Jim Stanley <JimS@Media-Services.Com>
Cc: xmlschema-dev@w3.org

Hi Jim,

The simplest thing is to move all the keys and keyref in the element 
that include your activity and prodCategory elements. In this way you 
have the declarations in scope. Assuming all the elements must have an 
unique elemID and the parent of activity and prodCategory is an element 
named document then the following should define your keys and keyref:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">

     <xs:element name="document">
         <xs:complexType>
             <xs:sequence>
                 <xs:element ref="prodCategory" maxOccurs="unbounded"/>
                 <xs:element ref="activity" maxOccurs="unbounded"/>
             </xs:sequence>
         </xs:complexType>

         <xs:key name="prodCategory.PK">
             <xs:selector xpath="prodCategory"/>
             <xs:field xpath="catName"/>
         </xs:key>
         <xs:key name="activityID.PK">
             <xs:selector xpath="activity"/>
             <xs:field xpath="activityID"/>
         </xs:key>
         <xs:key name="prodElement.PK">
             <xs:selector xpath="prodCategory/prodElement"/>
             <xs:field xpath="elemID"/>
         </xs:key>

         <xs:keyref name="elemRef.FK" refer="prodElement.PK">
             <xs:selector xpath="activity"/>
             <xs:field xpath="elemRef"/>
         </xs:keyref>
     </xs:element>


     <xs:element name="prodCategory" type="prodCategory"/>
     <xs:complexType name="prodCategory">
         <xs:sequence>
             <xs:element name="catName" type="xs:string"/>
             <xs:element ref="prodElement" maxOccurs="unbounded"/>
         </xs:sequence>
     </xs:complexType>

     <xs:element name="prodElement" type="prodElement"/>
     <xs:complexType name="prodElement">
         <xs:sequence>
             <xs:element name="elemID" type="xs:int"/>
             <xs:element name="elemName" type="xs:string"/>
             <xs:element name="elemOrder" type="xs:int"/>
             <xs:element name="elemQuantity" type="xs:int" default="1"/>
         </xs:sequence>
     </xs:complexType>

     <xs:element name="activity" type="activity"/>
     <xs:complexType name="activity">
         <xs:sequence>
             <xs:element name="activityID" type="xs:int"/>
             <xs:element name="elemRef" type="xs:int" 
maxOccurs="unbounded"/>
         </xs:sequence>
     </xs:complexType>
</xs:schema>


Hope that helps,
George
-----------------------------------------------
George Cristian Bina
<oXygen/> XML Editor & XSLT Editor/Debugger
http://www.oxygenxml.com
Received on Friday, 30 July 2004 04:26:26 UTC

This archive was generated by hypermail 2.3.1 : Wednesday, 5 February 2014 07:15:10 UTC