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:element ref="prodCategory" maxOccurs="unbounded"/>
                 <xs:element ref="activity" maxOccurs="unbounded"/>

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

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

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

     <xs:element name="prodElement" type="prodElement"/>
     <xs:complexType name="prodElement">
             <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:element name="activity" type="activity"/>
     <xs:complexType name="activity">
             <xs:element name="activityID" type="xs:int"/>
             <xs:element name="elemRef" type="xs:int" 

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

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 23:15:22 UTC