Martin said:
Have a look at ID/IDREF and key/keyref.
Thanks!
After a lot of looking around for working and well-explained examples, I managed to get the following (in case someone is looking for something similar):
<xsd:schema xmlns:xsd="
http://www.w3.org/2001/XMLSchema"> <xsd:element name="ImportData"> <xsd:complexType> <xsd:sequence> .. definitions of the "locationType" and "location" elements .. </xsd:sequence> </xsd:complexType>
<xsd:key name="locationTypeId">
<xsd:annotation>
<xsd:documentation>Within the whole data set, every location type must have a unique ID attribute</xsd:documentation> </xsd:annotation> <xsd:selector xpath=".//locationType"/> <xsd:field xpath="@id"/> </xsd:key>
<xsd:key name="locationId">
<xsd:annotation>
<xsd:documentation>Within the whole data set, every location must have a unique ID attribute</xsd:documentation> </xsd:annotation> <xsd:selector xpath=".//location"/> <xsd:field xpath="@id"/> </xsd:key>
<xsd:keyref name="locationIdRef" refer="locationTypeId"> <xsd:annotation> <xsd:documentation>Locations must be of an existing locationType</xsd:documentation> </xsd:annotation> <xsd:selector xpath=".//location"/> <xsd:field xpath="@type"/> </xsd:keyref>
.... The rest of the Schema ...
A few notes:
- <key> is basically the same as <unique>, except that the elements and/or attributes referenced in the <field> XPath _has_ to exist, i.e.
they cannot be empty.