Reputation: 40002
I'm not sure XSD has this ability, but if it does I can't figure out how to do it. When submission type is "submit_one", reports can only have the values A, B, or C. When the submission type is "submit_two", reports can only have the values X, Y, or Z. How can I represent this in an XML Schema Definition file?
These would both be valid XML files using this Schema.
<submission type="submit_one">
<reports>
<report>A</report>
<report>B</report>
</reports>
</submission>
<submission type="submit_two">
<reports>
<report>X</report>
<report>Y</report>
</reports>
</reports>
This would not be a valid xml
<submission type="submit_one">
<reports>
<report>X</report>
<report>Z</report>
</reports>
</submission>
Upvotes: 2
Views: 3268
Reputation: 21638
If you're doing only XSD 1.0, then it is not possible. If you're willing to combine an XSD 1.0 processor with a Schematron engine, then you could do it.
Alternatively, if you have access to an XSD 1.1 processor, then you could resolve it with an <xsd:assert/> or you could use type alternatives. Take a look here for additional information.
Upvotes: 3
Reputation: 31760
For the kind of validation you want to do you need to define two separate "Submission" types, one for one "restriction-set" and one for the other.
Unfortunately by doing this you will not be able to share the same node name across two different types at the same position in the schema.
Upvotes: 0