XSD newbie: Element based choice.

Discussion in 'XML' started by BLUE, Mar 23, 2007.

  1. BLUE

    BLUE Guest

    Suppose I have an XML file like this:

    <type>...</type>
    <positionID>...</positionID>
    <category>...</category>


    I want to specify in my XML Schema that:

    - if "type" is "One" I must have
    <positionID>A_STRING</positionID>

    - if "type" is "Two" I must have
    <positionID>
    <zoneID>A_POSITIVE_NUM</zoneID>
    <sectorID>A_POSITIVE_NUM</sectorID>
    <cellID>A_POSITIVE_NUM</cellID>
    </positionID>

    - if "type" is "Three" I must have
    no category or empty category

    - if "type" is "Four" I must have
    the same thing as for case "Two" and "Three"


    If this is not possible can I check this from my application or it would be
    a semantic error and it would be better to separate the two schemas?


    Thank you for any help!
    Luigi.
    BLUE, Mar 23, 2007
    #1
    1. Advertising

  2. "BLUE" <blue> wrote in message
    news:460446d5$0$37193$...
    > Suppose I have an XML file like this:
    >
    > <type>...</type>
    > <positionID>...</positionID>
    > <category>...</category>


    That's not a well-formed XML document. You need root element around all of
    those.

    > I want to specify in my XML Schema that:
    >
    > - if "type" is "One" I must have
    > <positionID>A_STRING</positionID>
    >
    > - if "type" is "Two" I must have
    > <positionID>
    > <zoneID>A_POSITIVE_NUM</zoneID>
    > <sectorID>A_POSITIVE_NUM</sectorID>
    > <cellID>A_POSITIVE_NUM</cellID>
    > </positionID>
    >
    > - if "type" is "Three" I must have
    > no category or empty category
    >
    > - if "type" is "Four" I must have
    > the same thing as for case "Two" and "Three"
    >
    >
    > If this is not possible can I check this from my application or it would
    > be a semantic error and it would be better to separate the two schemas?


    XML Schema cannot describe this situation. You'll have to check yourself.

    John
    John Saunders, Mar 23, 2007
    #2
    1. Advertising

  3. These constraints are called co-occurrence constraints and cannot be
    specified using XML Schema. You can embed Schematron rules in your schema to
    specify the same.
    For more information on Schematron, check the following:
    http://xml.ascc.net/resource/schematron/
    http://www.xml.com/pub/a/2000/11/22/schematron.html

    Thanks,
    Priya

    "BLUE" <blue> wrote in message
    news:460446d5$0$37193$...
    > Suppose I have an XML file like this:
    >
    > <type>...</type>
    > <positionID>...</positionID>
    > <category>...</category>
    >
    >
    > I want to specify in my XML Schema that:
    >
    > - if "type" is "One" I must have
    > <positionID>A_STRING</positionID>
    >
    > - if "type" is "Two" I must have
    > <positionID>
    > <zoneID>A_POSITIVE_NUM</zoneID>
    > <sectorID>A_POSITIVE_NUM</sectorID>
    > <cellID>A_POSITIVE_NUM</cellID>
    > </positionID>
    >
    > - if "type" is "Three" I must have
    > no category or empty category
    >
    > - if "type" is "Four" I must have
    > the same thing as for case "Two" and "Three"
    >
    >
    > If this is not possible can I check this from my application or it would
    > be a semantic error and it would be better to separate the two schemas?
    >
    >
    > Thank you for any help!
    > Luigi.
    >
    Priya Lakshminarayanan, Mar 29, 2007
    #3
    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.
Similar Threads
  1. Mickey Segal
    Replies:
    0
    Views:
    856
    Mickey Segal
    Feb 2, 2004
  2. jmc
    Replies:
    0
    Views:
    1,789
  3. Matthet
    Replies:
    2
    Views:
    662
    Matthet
    Sep 24, 2003
  4. miles.jg
    Replies:
    16
    Views:
    857
    Alf P. Steinbach
    Nov 14, 2007
  5. PeteOlcott
    Replies:
    1
    Views:
    934
    Mukul Gandhi
    Feb 5, 2009
Loading...

Share This Page