Re: More Key/Keyref Questions

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