8

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?

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

4 Comments

Yes, I undersand.... I though there could be some xpath magic I can do in either key or keyref elements to avoid redesigning the xml format.....
Well, @artur, then please look at this QA: stackoverflow.com/questions/8688864/…
the question you linked to is more about expressing permutation of few known values, what I am dealing here is identity checks, which are not the same. I need to validate that each item in the list is a primary key on certain element in the doc. Thanks though
What about xs:IDREFS?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.