I’m trying to make an XSD that specifies that an <a> element must have 4 child <b> elements, which contain the c attributes 1 through 4, as follows:
Valid:
<a>
<b c="1" d="valueof1" />
<b c="2" d="valueof2" />
<b c="3" d="valueof3" />
<b c="4" d="valueof4" />
</a>
Not valid:
<a>
<b c="1" d="valueof1" />
<b c="1" d="valueof1_other" />
<b c="3" d="valueof3" />
<b c="4" d="valueof4" />
</a>
Not valid:
<a>
<b c="1" d="valueof1" />
<b c="2" d="valueof2" />
<b c="3" d="valueof3" />
<b c="4" d="valueof4" />
<b c="5" d="valueof5" />
</a>
Is this possible? The closest thing I could find is the all element, but that only appears to work for specifying unique elements, not attribute values.
You can enforce the first rule by declaring element
bwithminOccurs=4andmaxOccurs=4, like so:However, you can not use XSD to enforce the second rule. If you really want to do that, you can, for example, replace the 4
belements with elementsb1,b2,b3, andb4, each of which would implicitly represent thecattributes 1 through 4, respectively.