Reputation: 591
Using xsd:key and xsd:keyref, we can validate that a value in one element is defined in another element. We do this in our schema to ensure that valid values are used, but we would also like to be able to validate that all of the values specified in one element are used in children of another element, i.e.:
<elementList>
<listEntry>Entry1</listEntry>
<listEntry>Entry2</listEntry>
<listEntry>Entry3</listEntry>
</elementList>
<elementOperations>
<operation name="Entry1">Operation1</operation>
<operation name="Entry3">Operation3</operation>
</elementOperations>
In this example, we would like there to be a validation error because there is not an element whose name attribute specifies Entry2. Is this possible at all with XSD Schema validation?
Upvotes: 1
Views: 79
Reputation: 21658
It is possible if you're not allowing duplicate values in the operation names; in which case simply add another key/keyref pair which points the other way around (i.e. the key is now the operation name).
If duplicates are possible, then you cannot do it with XSD 1.0 alone - Schematron can help you here. Alternatively, if you're working in an environment where XSD 1.1 is supported, then use XSD 1.1's xsd:assert
.
Upvotes: 2