Martin Honnen wrote:
Victor wrote:
I have a Schema with some elements which are "types" or objects, and
some elements which correspond to instances of the types. How can I
specify that a <locationInstan ce> must have an attribute "type" which
equals any one of the "id" attributes of the <locationType>s ?
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="ImportDat a">
<xsd:complexTyp e>
<xsd:sequence >
.. definitions of the "locationTy pe" and "location" elements ..
</xsd:sequence>
</xsd:complexType >
<xsd:key name="locationT ypeId">
<xsd:annotation >
<xsd:documentat ion>Within the whole data set, every location
type must have a unique ID attribute</xsd:documentati on>
</xsd:annotation>
<xsd:selector xpath=".//locationType"/>
<xsd:field xpath="@id"/>
</xsd:key>
<xsd:key name="locationI d">
<xsd:annotation >
<xsd:documentat ion>Within the whole data set, every location
must have a unique ID attribute</xsd:documentati on>
</xsd:annotation>
<xsd:selector xpath=".//location"/>
<xsd:field xpath="@id"/>
</xsd:key>
<xsd:keyref name="locationI dRef" refer="location TypeId">
<xsd:annotation >
<xsd:documentat ion>Locations must be of an existing
locationType</xsd:documentati on>
</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.
--
Victor