How to restrict elements by reference to another element using XML schema

Piers Chivers

Usenet Archive
Joined
Feb 18, 2004
Messages
3
Reaction score
0
Hi,
I need to restrict the allowed included elements dependent upon the value of another element. How do I do this using XML Schema?

For example, the XML

<Petshop>
<Kind>Dog</Kind>
<Breeds>
<Breed>Poodle</Breed>
<Breed>Alsatian</Breed>
</Breeds>
</Petshop>

is valid because the element <Breeds> is allowed when the element <Kind> has a value of 'Dog'. However

<Petshop>
<Kind>Fish</Kind>
<Breeds>
<Breed>Poodle</Breed>
<Breed>Alsatian</Breed>
</Breeds>
</Petshop>

is not valid because the element <Breeds> is not allowed when the element <Kind> has a value of 'Fish'.

How do I describe this using XML schema? Also, how would I say the element <Breeds> is mandated when the value is 'Dog', and the element <WaterType> is mandated when the value is 'Fish'?

Many thanks,
Piers
 

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
548,208
Messages
3,104,799
Members
249,594
Latest member
henrywalsh

Latest Threads

Top