Xml Schema OR, XOR

Discussion in 'XML' started by Verticon::, May 10, 2007.

  1. Verticon::

    Verticon:: Guest

    I have two situations here.

    1. XOR: I found I can use the 'choice' type to handle that.
    2. OR: I don't know how to do

    All three of these are valid:
    <root>
    <A />
    <B />
    </root>

    <root>
    <A />
    </root>

    <root>
    <B />
    </root>

    This would NOT be valid:
    <root>
    </root>

    How would I lay out the schema for the OR situation here?
     
    Verticon::, May 10, 2007
    #1
    1. Advertisements

  2. Verticon:: wrote:
    > How would I lay out the schema for the OR situation here?


    "One or more instances of the choice" would permit any mixture of A's
    and B's but reject the empty case.

    If you want to allow ONLY A, B, or AB (not AAB, ABA, etc.)... I think
    you need to spell out those three options as separate choices. XML
    Schema doesn't have the ability to say "exclude/require X if Y was present".


    --
    Joe Kesselman / Beware the fury of a patient man. -- John Dryden
     
    Joseph Kesselman, May 10, 2007
    #2
    1. Advertisements

  3. Verticon::

    Verticon:: Guest

    I just tried to do that. I added a new choice group with A, B, and a
    group of A and B. Came back with ambiguous content errors in the
    schema; redefining existing nodes.
     
    Verticon::, May 10, 2007
    #3
  4. Verticon:: wrote:
    > I just tried to do that. I added a new choice group with A, B, and a
    > group of A and B. Came back with ambiguous content errors in the
    > schema; redefining existing nodes.


    That doesn't wholly surprise me, I'm afraid.

    I suspect the best you can do is to set zero-to-two on the choice, and
    check that they aren't the same in your application code. I'd love to
    find out I'm wrong.

    See recent discussion of the goals and limitations of XML Schema.


    --
    () ASCII Ribbon Campaign | Joe Kesselman
    /\ Stamp out HTML e-mail! | System architexture and kinetic poetry
     
    Joe Kesselman, May 11, 2007
    #4
  5. Verticon:: wrote:
    > I have two situations here.
    >
    > 1. XOR: I found I can use the 'choice' type to handle that.
    > 2. OR: I don't know how to do
    >
    > All three of these are valid:
    > <root>
    > <A />
    > <B />
    > </root>
    >
    > <root>
    > <A />
    > </root>
    >
    > <root>
    > <B />
    > </root>
    >
    > This would NOT be valid:
    > <root>
    > </root>
    >
    > How would I lay out the schema for the OR situation here?


    This should do:

    <xs:element name="root">
    <xs:complexType>
    <xs:choice>
    <xs:sequence>
    <xs:element name="A"/>
    <xs:element name="B" minOccurs="0"/>
    </xs:sequence>
    <xs:element name="B"/>
    </xs:choice>
    </xs:complexType>
    </xs:element>

    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
     
    Martin Honnen, May 11, 2007
    #5
  6. Martin Honnen wrote:
    > <xs:element name="root">
    > <xs:complexType>
    > <xs:choice>
    > <xs:sequence>
    > <xs:element name="A"/>
    > <xs:element name="B" minOccurs="0"/>
    > </xs:sequence>
    > <xs:element name="B"/>
    > </xs:choice>
    > </xs:complexType>
    > </xs:element>


    Looks reasonable to me. Kicking myself slightly for not having
    immediately seen that solution; like I said, I haven't been using schema
    enough recently.

    --
    () ASCII Ribbon Campaign | Joe Kesselman
    /\ Stamp out HTML e-mail! | System architexture and kinetic poetry
     
    Joe Kesselman, May 13, 2007
    #6
    1. Advertisements

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. Markus
    Replies:
    1
    Views:
    1,919
    Markus
    Nov 23, 2005
  2. Fred Smith
    Replies:
    1
    Views:
    1,195
    Martin Honnen
    Feb 5, 2004
  3. Hari Om
    Replies:
    1
    Views:
    588
    Martin SChukrazy
    Mar 2, 2004
  4. Andy
    Replies:
    0
    Views:
    706
  5. Stanimir Stamenkov
    Replies:
    3
    Views:
    1,565
    Stanimir Stamenkov
    Apr 25, 2005
  6. Replies:
    3
    Views:
    4,544
  7. Matt
    Replies:
    3
    Views:
    566
    Bob Barrows [MVP]
    Apr 23, 2004
  8. Replies:
    5
    Views:
    1,670
    Brian McCauley
    Nov 29, 2006
Loading...