Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


More Key/Keyref Questions

From: "Jim Stanley" <JimS@--------------.--->
To: <xmlschema-dev@--.--->
Date: 7/27/2004 6:58:00 AM
Hello all,

Every time I think I've got the XML schema keys and keyrefs, they
baffle me again.  A simplified scenario:

Categories have elements, each of which must have a unique ID. 
Activities reference these elements by ID, and an activity cannot have a
nonexistent element ID.

On the previous advice of  George (thanks much!), my simplified schema
looks something like this:

<xs:element name="prodCategory" type="prodCategory">
	<xs:key name="prodCategory.PK">
		<xs:selector xpath="."/>
		<xs:field xpath="catName"/>
	</xs:key>
	<xs:key name="CatElem.PK">
		<xs:selector xpath="prodElement"/>
		<xs:field xpath="elemID"/>
	</xs:key>
</xs:element>
<xs:complexType name="prodCategory">
	<xs:sequence>
		<xs:element name="catName" type="xs:string"/>
		<xs:element ref="prodElement" maxOccurs="unbounded"/>
	</xs:sequence>
</xs:complexType>

My udnerstanding, through George and plowing through the XML schema
spec, is that the above keys define uniqueness _within a category_ - in
other words, Category1 could not contain two elements with ID #1.

On to elements:

<xs:element name="prodElement" type="prodElement">
	<xs:key name="prodElement.PK">
		<xs:selector xpath="."/>
		<xs:field xpath="elemID"/>
	</xs:key>
</xs:element>
<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>

Do I need prodElement.PK as well to define uniqueness and referral
_across_ categories?  (In which case, perhaps I don't need CatElem.PK as
it defines essentially the same thing.)  Because my activity definition
needs to refer to unique elements in any category:

<xs:element name="activity" type="activity">
	<xs:key name="activityID.PK">
		<xs:selector xpath="."/>
		<xs:field xpath="activityID"/>
	</xs:key>
	<xs:keyref name="elemRef.FK" refer="prodElement.PK">
		<xs:selector xpath="."/>
		<xs:field xpath="elemRef"/>
	</xs:keyref>
</xs:element>
<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>

What I'm trying to do above is make sure that an activity can have any
number of elements, but they must be uniue ID's that exist somewhere in
some category.  I wish I were a little less dense at this - please be
patient with an XML newbie.

Jim Stanley
Media Services, Inc.

From rschloss@u...  Fri Jul 30 03:04:30 2004
Return-Path: <rschloss@u...>
X-Original-To: xmlschema-dev@li


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent