tags:

views:

77

answers:

2

I would like to set up an XSD such that it enforces something like a foreign key relationship. Here's an example:


<MappingElement Reference="MySourceElementName"/>

<SourceElement Name="MySourceElementName"/>

I would like to specify in the XSD that for any value assigned to the attribute "Reference" must also be a value of a Name attribute in a SourceElement tag. I know about enumerable restrictions, but the range of values for Name are open ended -- I simply need integrity between my Reference attributes and my Name attributes. Is there a way to express this with XSD?

+1  A: 

You use xs:key and xs:keyref.

Here's an example

skaffman
That did it -- thanks
JMarsch
A: 

You are looking for the IDREF/IDREFS and ID data types. the Name attribute would be of type ID and the Reference attribute of type IDREF

Hope that helps!

ID and IDREF are for use in a DTD, not a schema.
skaffman
I agree with the first, but it is used in XML Schema as well as far as me is taught.