XML Schema : How to ensure atleast one child element present ?

A

Abhinav

Hi,

I have the following document

<!-- This is the root -->
<orders>

<singleItemOrders>
</singleItemOrders>

<multipleItemOrders>
</multipleItemOrders>
</orders>

<orders> can contain 0 or 1 <singleItemOrders> as well as
<multipleItemOrders>. However, AT LEAST one of them _must_ be present.

I am not able to construct the schema to vaidate this. using

<all>
<element name="singleItemOrders" minOccurs="0" />
<element name="multipleItemOrders" minOccurs="0" />
</all>

The above is obviously wrong, as iit does not take care of the case when
both are absent :(

Any suggestions would be highly appreciated

TIA
Abhinav
 
A

Abhinav

Abhinav said:
Hi,

I have the following document

<!-- This is the root -->
<orders>

<singleItemOrders>
</singleItemOrders>

<multipleItemOrders>
</multipleItemOrders>
</orders>

<orders> can contain 0 or 1 <singleItemOrders> as well as
<multipleItemOrders>. However, AT LEAST one of them _must_ be present.

I am not able to construct the schema to vaidate this. using

<all>
<element name="singleItemOrders" minOccurs="0" />
<element name="multipleItemOrders" minOccurs="0" />
</all>

The above is obviously wrong, as iit does not take care of the case when
both are absent :(

Any suggestions would be highly appreciated

While waiting for answers, I did a more extensive search for some
pointers, and come up with the solution. Is it available at this line :
http://tinyurl.com/4eof7

so, my schema should be

<choice minOccurs="1" maxOccurs="2" >
<element name="singleItemOrders" minOccurs="0" />
<element name="multipleItemOrders" minOccurs="0" />
</choice>

Thanks anyways !
 

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

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top