XSD - how can I ensure the existance of a particular element with a given attribute?

StackOverflow https://stackoverflow.com/questions/283616

  •  08-07-2019
  •  | 
  •  

Question

I'm trying to add extra validation to jdpl process-definition files using XSD.

We have a couple of rules we want to add; but the one that's causing me problems is that there must exist one "node" element with it's "name" attribute = "Problem".

so this is valid:

<process-definition name='sample'>
    <node name="Problem">
    </node>
    <node name="Do Work">
    </node>
</process-definition>

and this isn't

<process-definition name='sample'>
    <node name="Do Work">
    </node>
</process-definition>

So, to summarise, the rules I need to enforce are

  • node attribute having the value "Problem"
  • existence of 1 node with name="Problem"
  • allowing any number of nodes with other names

Any ideas out there?

Was it helpful?

Solution

Sorry that's not possible with XSD.

Due to performance reasons XML-Schema is designed to never look ahead and never look back beyond the current node. That means that it must always be defined where the validator is in the schema-tree. And that makes requirements like this impossible to define with XSD.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top