xsd choice problem

Y

yonido

hi

my xml structure is:
<root>
<a></a>
<b></b>
</root>


a valid xml should be:
1. root element is mandatory.
2. <a> OR <b> OR BOTH, but AT LEAST one of them.
3. cant have 2 <a>'s or 2 <b>'s.


i've tried everything and cant get it to work.
closest things:
1. xsd:choice with maxOccours = 2 for the xsd:choice element. this
works, but 2 <a>'s are legal.
if u add maxOccurs=1 for the <a> element, it ignores it for some
reason.
2. xsd:sequence with 2 elements, a & b - where each gets minOccurs=0,
maxOccurs=1. This works, but an empty <root></root> is valid too. i
need at least one child.
so i tried adding minOccurs=1 for the xsd:sequence but it ignores it
to.
3. also tried playing with groups but nada.


I dont think it should be that complicated..
any ideas?
thanks in advance.
 
G

GeorgeBina

Hi,
a valid xml should be:
1. root element is mandatory.
2. <a> OR <b> OR BOTH, but AT LEAST one of them.
3. cant have 2 <a>'s or 2 <b>'s.

The content model is
a | b | (a, b)

but this is ambiguous. You can write this in a non ambiguous way as

(a, b?) | b

In XML Schema that will be

<xs:choice>
<xs:sequence>
<xs:element ref="a"/>
<xs:element ref="b" minOccurs="0"/>
</xs:sequence>
<xs:element ref="b"/>
</xs:choice>

Regards,
George
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,045
Latest member
DRCM

Latest Threads

Top