Harry Lime
Harry Lime

Reputation: 29576

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

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

Any ideas out there?

Upvotes: 2

Views: 292

Answers (1)

TToni
TToni

Reputation: 9391

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.

Upvotes: 1

Related Questions