Reputation: 21
What is the correct syntax for XSD schema to define the following restriction:
In the list of elements we have to specify that attribute can contain value of "c" unlimited number of times, but value of "b" - the zero or only one time.
For example, the correct xml looks like this:
<root>
<elem atr="c">111</elem>
<elem atr="c">222</elem>
<elem atr="b">333</elem>
<elem atr="c">444</elem>
<elem atr="c">555</elem>
</root>
And incorrect one is:
<root>
<elem atr="c">111</elem>
<elem atr="c">222</elem>
<elem atr="b">333</elem>
<elem atr="c">444</elem>
<elem atr="b">555</elem>
</root>
Upvotes: 0
Views: 121
Reputation: 43709
I think you can't do that. The closest is xsd:key:
<xsd:key name="idKey">
<xsd:selector xpath="elem"/>
<xsd:field xpath="@atr"/>
</xsd:key>
But it's not exactly what you want.
XML Schema generally has very limited means to define value-dependent constraints. Take a look at the Schematron.
Upvotes: 3
Reputation: 4779
As far as I know this is impossible. You can make atr
unique though...
Upvotes: 0