tags:

views:

33

answers:

2

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>
A: 

As far as I know this is impossible. You can make atr unique though...

Yaneeve
+3  A: 

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.

lexicore