0

Given the following xml structure:

<root>
  <definitions>
    <definition key="def1" group="group1" isExclusiveInGroup="true" />
    <definition key="def2" group="group1" isExclusiveInGroup="false" />
    <definition key="def3" group="group1" isExclusiveInGroup="false" />
    <definition key="def4" group="group2" isExclusiveInGroup="true" />
  </definitions>
  <items>
    <item key="item1" definitionKey="def1" />
    <item key="item2" definitionKey="def4" />
  </items>
</root>

What I want to validate, in english:

  1. It is acceptable for the items element to contain an item element referencing def2 and another item element referencing def3. They are not exclusive within group1.

  2. It is acceptable for the items element to contain an item element referencing def1 and another item element referencing def4. They are part of different groups, thus their exclusivity does not conflict.

  3. It is not acceptable for the items element to contain an item element referencing def1 and another item element referencing any other definition that has a group attribute equal to group1. Def1 is exclusive to it's group so there can not be any other items referencing a definition within the same group

What xsd structures/elements would I use to enforce such a specification?

Nathan
  • 503
  • 3
  • 10
  • What's your question? Hint: It's too broad if it's, "Would you write an XSD for me to my specification?" – kjhughes Apr 04 '16 at 23:05
  • What xsd structures/elements would I use to enforce such a specification? I am aware of xsd:key and xsd:unique, but I don't know how to approach enforcing a constraint like the one I described. – Nathan Apr 04 '16 at 23:07
  • 1
    With the complexity of your constraints, you're probably going to need to use `xsd:assert`, which requires XSD 1.1. – kjhughes Apr 04 '16 at 23:18
  • Unfortunately, I am unable to use XSD 1.1. I am not particularly familiar with XPath, but is there no query that could be written that would allow me to use the `xsd:unique` element to achieve the desired constraint? – Nathan Apr 04 '16 at 23:44
  • 1
    There is no way of writing the constraint using xsd:unique given the severely restricted subset of XPath 1.0 that is permitted in that construct. – Michael Kay Apr 05 '16 at 23:18

1 Answers1

1

This is beyond the capabilities of XSD 1.0. You will need to use a different validation technology, for example XSD 1.1 or Schematron.

Michael Kay
  • 156,231
  • 11
  • 92
  • 164