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

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,821
Latest member
AleidaSchi

Latest Threads

Top