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

Discussion in 'XML' started by Piers Chivers, Feb 18, 2004.

  1. 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
     
    Piers Chivers, Feb 18, 2004
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.

Share This Page