Xml Schema OR, XOR

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Verticon::

    Xml Schema OR, XOR

    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?

  • Joseph Kesselman

    #2
    Re: Xml Schema OR, XOR

    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

    Comment

    • Verticon::

      #3
      Re: Xml Schema OR, XOR

      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.

      Comment

      • Joe Kesselman

        #4
        Re: Xml Schema OR, XOR

        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

        Comment

        • Martin Honnen

          #5
          Re: Xml Schema OR, XOR

          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

          Comment

          • Joe Kesselman

            #6
            Re: Xml Schema OR, XOR

            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

            Comment

            Working...