Search code examples
xmlxsdxsd-1.0

Require Specific Element Values depending on Values of Parent's Sibling's Children


I am trying to work out the schema for requiring that the values of instances of an element are sequential without any gaps (although the order does not matter).

Valid:

<Racks>
  <Rack>
    <RackNumber>1</RackNumber>
  </Rack>
  <Rack>
    <RackNumber>2</RackNumber>
  </Rack>
  <Rack>
    <RackNumber>3</RackNumber>
  </Rack>
</Racks>

Valid:

<Racks>
  <Rack>
    <RackNumber>2</RackNumber>
  </Rack>
  <Rack>
    <RackNumber>3</RackNumber>
  </Rack>
  <Rack>
    <RackNumber>1</RackNumber>
  </Rack>
</Racks>

Not Valid:

<Racks>
  <Rack>
    <RackNumber>1</RackNumber>
  </Rack>
  <Rack>
    <RackNumber>3</RackNumber>
  </Rack>
</Racks>

Is enforcing this possible with XSD 1.0? If so, then can someone point me in the right direction?


Solution

  • There's not convenient way to do this in XSD 1.0. In XSD 1.1 you could use assertions (on the parent Racks element) to enforce the constraint. But if it were me, I'd change the XML to entail less redundancy and less interdependency between adjacent elements.