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

P

Piers Chivers

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
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top