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. Advertising

  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. Advertising

  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. 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. Markus
    Replies:
    1
    Views:
    1,611
    Markus
    Nov 23, 2005
  2. Fred Smith
    Replies:
    1
    Views:
    967
    Martin Honnen
    Feb 5, 2004
  3. Stanimir Stamenkov
    Replies:
    3
    Views:
    1,295
    Stanimir Stamenkov
    Apr 25, 2005
  4. Replies:
    3
    Views:
    2,951
  5. Martin Honnen
    Replies:
    0
    Views:
    1,496
    Martin Honnen
    Aug 13, 2009
Loading...

Share This Page