Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

using keyref in xml schema for an attribute with a list of values

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?

like image 459
artur Avatar asked Jan 08 '13 15:01

artur


1 Answers

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

like image 158
Andremoniy Avatar answered Nov 08 '22 01:11

Andremoniy