I am trying to design a schema for validating an xml format that is already used in an application (not much room for redesigning the xml).
I am trying to utilize the key and keyref elements of the xml schema dictionary to validate identity constraints.
One particular problem is with the way the xml models one to many relationship
<spaceships>
<spaceship guns="gun1 gun2 gun3"/>
</spaceships>
<guns>
<gun id="gun1"/>
<gun id="gun2"/>
<gun id="gun3"/>
</guns>
I came up with this pair of key/keyref in my schema
<xs:key name="gunKey">
<xs:selector xpath="guns/gun" />
<xs:field xpath="@id" />
</xs:key>
<xs:keyref name="gunRef" refer="gunKey">
<xs:selector xpath="spaceships/spaceship" />
<xs:field xpath="@guns" />
</xs:keyref>
This doesn't validate with xerces protesting:
Key 'gunRef' with value 'gun1 gun2 gun3' not found for identity constraint of element.
Is there anyway of expressing in schema that the value of the list is comma separated list of references to another entity and still get the benefit of identity constraint validation?
I'm afraid, that you can not create such reference for an attribute like guns="gun1 gun2 gun3"
because gun1 gun2 gun3
is a simple string which is not automatically divided into 3 separate parts.
EDIT 1: If you want to match such attributes, look at this QA: XML schema; multiple from a list of valid attribute values
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With