Schema restrictions on objects and instances

Victor (5)

Usenet Archive
Joined
May 7, 2004
Messages
11
Reaction score
0
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 <locationInstance> must have an attribute "type" which equals any one of the "id" attributes of the <locationType>s?
 

Martin Honnen

Usenet Archive
Joined
Apr 8, 2000
Messages
6,174
Reaction score
0
Victor said:
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 <locationInstance> 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.
 

Victor (5)

Usenet Archive
Joined
May 7, 2004
Messages
11
Reaction score
0
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
548,042
Messages
3,104,223
Members
248,131
Latest member
Tonypshaw1

Latest Threads

Top