Help needed with complex schema definition

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Gili Korman

    #1

    Help needed with complex schema definition

    Hi all,

    I need to create an XSD schema that will reperesent the following:

    <LIST>
    <ITEM1/> 0-unbounded
    <ITEM3/> 0-unbounded
    </LIST>

    or

    <LIST>
    <ITEM2/> 0-unbounded
    <ITEM3/> 0-unbounded
    </LIST>

    The problem is that within the LIST item, the order of the elements
    does not matter! I found that I can't use the all model with the
    choice model as parent.
    Other solutions I tried resulted in ambigouos definition of the ITEM3
    element due to "Unique Particle Attribution rule".

    This is the current unsatisfactory schema, since it contains sequence
    which forces unwanted order:

    <xs:complexTy pe name="ListType" >
    <xs:sequence>
    <xs:choice minOccurs="0">
    <xs:element name="ITEM1" type="ITEM1Type " minOccurs="0"
    maxOccurs="unbo unded"/>
    <xs:element name="ITEM2" type="ITEM2Type " minOccurs="0"
    maxOccurs="unbo unded"/>
    </xs:choice>
    <xs:element name="ITEM3" type="ITEM3Type " minOccurs="0"
    maxOccurs="unbo unded"/>
    </xs:complexType>

    Any ideas?

    Thanks in advance,

    Gili Korman
    ITG
  • Klaus Johannes Rusch

    #2
    Re: Help needed with complex schema definition

    Gili Korman wrote:
    [color=blue]
    > The problem is that within the LIST item, the order of the elements
    > does not matter! I found that I can't use the all model with the
    > choice model as parent.
    > Other solutions I tried resulted in ambigouos definition of the ITEM3
    > element due to "Unique Particle Attribution rule".
    >
    > This is the current unsatisfactory schema, since it contains sequence
    > which forces unwanted order:[/color]

    How about

    <xs:element name="list">
    <xs:complexType >
    <xs:sequence minOccurs="0" maxOccurs="unbo unded">
    <xs:choice>
    <xs:element ref="item1" minOccurs="1" maxOccurs="1"/>
    <xs:element ref="item2" minOccurs="1" maxOccurs="1"/>
    <xs:element ref="item3" minOccurs="1" maxOccurs="1"/>
    </xs:choice>
    </xs:sequence>
    </xs:complexType>
    </xs:element>



    --
    Klaus Johannes Rusch
    KlausRusch@atme dia.net



    Comment

    • Eric Sirois

      #3
      Re: Help needed with complex schema definition

      Hello if you want the item to appear in any order any number of times
      try the following:

      <xs:complexTy pe name="ListType" >
      <xs:choice minOccurs="0" maxOccurs="unbo unded">
      <xs:element name="ITEM1" type="ITEM1Type " />
      <xs:element name="ITEM2" type="ITEM2Type " />
      <xs:element name="ITEM3" type="ITEM3Type " />
      </xs:choice>
      </xs:complexType>

      or are you trying to model that ITEM1 and ITEM2 can only appear once
      along with ITEM3, but there should be able to appear in any order any
      number of times.

      Is this valid:
      <LIST>
      <ITEM3/>
      <ITEM1/>
      <ITEM1/>
      </LIST>

      but not:

      <LIST>
      <ITEM3/>
      <ITEM1/>
      <ITEM2/>
      </LIST>

      Kind regards,
      Eric

      Gili Korman wrote:[color=blue]
      > Hi all,
      >
      > I need to create an XSD schema that will reperesent the following:
      >
      > <LIST>
      > <ITEM1/> 0-unbounded
      > <ITEM3/> 0-unbounded
      > </LIST>
      >
      > or
      >
      > <LIST>
      > <ITEM2/> 0-unbounded
      > <ITEM3/> 0-unbounded
      > </LIST>
      >
      > The problem is that within the LIST item, the order of the elements
      > does not matter! I found that I can't use the all model with the
      > choice model as parent.
      > Other solutions I tried resulted in ambigouos definition of the ITEM3
      > element due to "Unique Particle Attribution rule".
      >
      > This is the current unsatisfactory schema, since it contains sequence
      > which forces unwanted order:
      >
      > <xs:complexTy pe name="ListType" >
      > <xs:sequence>
      > <xs:choice minOccurs="0">
      > <xs:element name="ITEM1" type="ITEM1Type " minOccurs="0"
      > maxOccurs="unbo unded"/>
      > <xs:element name="ITEM2" type="ITEM2Type " minOccurs="0"
      > maxOccurs="unbo unded"/>
      > </xs:choice>
      > <xs:element name="ITEM3" type="ITEM3Type " minOccurs="0"
      > maxOccurs="unbo unded"/>
      > </xs:complexType>
      >
      > Any ideas?
      >
      > Thanks in advance,
      >
      > Gili Korman
      > ITG[/color]

      Comment

      • C. M. Sperberg-McQueen

        #4
        Re: Help needed with complex schema definition

        gilik@itgil.com (Gili Korman) writes:
        [color=blue]
        > Hi all,
        >
        > I need to create an XSD schema that will reperesent the following:
        >
        > <LIST>
        > <ITEM1/> 0-unbounded
        > <ITEM3/> 0-unbounded
        > </LIST>
        >
        > or
        >
        > <LIST>
        > <ITEM2/> 0-unbounded
        > <ITEM3/> 0-unbounded
        > </LIST>[/color]

        I'm not sure what this is trying to say. Can you try again?
        [color=blue]
        > The problem is that within the LIST item, the order of the elements
        > does not matter![/color]

        Do you mean "it does not matter" in the sense that all possible
        orders should be allowed in the input? or in the sense that
        the order cannot possibly carry any information? (If the order
        cannot possibly carry any information, then a fixed order is
        usually a good way to go.)
        [color=blue]
        > Any ideas?[/color]

        Not until I understand better what it is you're trying to do.

        -C. M. Sperberg-McQueen
        World Wide Web Consortium

        Comment

        • Gili Korman

          #5
          Re: Help needed with complex schema definition

          cmsmcq@acm.org (C. M. Sperberg-McQueen) wrote in message news:<m2he31oq2 u.fsf@acm.org>. ..[color=blue]
          > gilik@itgil.com (Gili Korman) writes:
          >[color=green]
          > > Hi all,
          > >
          > > I need to create an XSD schema that will reperesent the following:
          > >
          > > <LIST>
          > > <ITEM1/> 0-unbounded
          > > <ITEM3/> 0-unbounded
          > > </LIST>
          > >
          > > or
          > >
          > > <LIST>
          > > <ITEM2/> 0-unbounded
          > > <ITEM3/> 0-unbounded
          > > </LIST>[/color]
          >
          > I'm not sure what this is trying to say. Can you try again?
          >[color=green]
          > > The problem is that within the LIST item, the order of the elements
          > > does not matter![/color]
          >
          > Do you mean "it does not matter" in the sense that all possible
          > orders should be allowed in the input? or in the sense that
          > the order cannot possibly carry any information? (If the order
          > cannot possibly carry any information, then a fixed order is
          > usually a good way to go.)
          >[color=green]
          > > Any ideas?[/color]
          >
          > Not until I understand better what it is you're trying to do.
          >
          > -C. M. Sperberg-McQueen
          > World Wide Web Consortium[/color]


          Sorry if I have been ambigouos, let me try to explain my list
          constraints:

          A. ITEM1 and ITEM2 can not co-exist in the list.
          B. The list can contain any number of ITEM1 (0-unbounded) OR
          any number of ITEM2 (0-unbounded), but only one of the types in a
          list.
          C. ITEM3 can also appear in the list, any number of times
          (0-unbounded), with
          or without the list having other elements.
          D. The order of the list does not carry any information, and so it
          does not
          matter.

          So, Klaus and Eric's schemas will not be good because they allow ITEM1
          and ITEM2 types in the same list.

          To Eric:

          <LIST>
          <ITEM3/>
          <ITEM1/>
          <ITEM2/>
          </LIST>

          is not OK.

          <LIST>
          <ITEM3/>
          <ITEM1/>
          <ITEM1/>
          </LIST>

          is OK.

          Thanks for your input, hoping for salvation...

          Comment

          • Gili Korman

            #6
            Re: Help needed with complex schema definition

            I would like to stress that since the order of the items in the list
            does not matter, I am required to allow any order - and that is the
            real problem !

            Comment

            • C. M. Sperberg-McQueen

              #7
              Re: Help needed with complex schema definition

              gilik@itgil.com (Gili Korman) writes:
              [color=blue]
              > ..., let me try to explain my list
              > constraints:
              >
              > A. ITEM1 and ITEM2 can not co-exist in the list.
              > B. The list can contain any number of ITEM1 (0-unbounded) OR
              > any number of ITEM2 (0-unbounded), but only one of the types in a
              > list.
              > C. ITEM3 can also appear in the list, any number of times
              > (0-unbounded), with
              > or without the list having other elements.
              > D. The order of the list does not carry any information, and so it
              > does not matter.
              >
              > So, Klaus and Eric's schemas will not be good because they allow ITEM1
              > and ITEM2 types in the same list.[/color]

              Well, I repeat what I said earlier: if the order of the items in the
              list does not carry any information, it is usually better practice to
              specify a fixed order. Otherwise, you wind up with fierce, protracted
              arguments between people who want to argue that

              <LIST1/><LIST1/><LIST3/>

              must be treated subtly differently from

              <LIST3/><LIST1/><LIST1/>

              or

              <LIST1/><LIST3/><LIST1/>

              and people who argue, on the contrary, that because the order of
              items carries no information, these must NOT be treated separately.
              It is better to nip such disagreements in the bud.

              I am almost unwilling to tell you how to do what you say you want to
              do, on the grounds that I am convinced you shouldn't do it, but if you
              are determined to provide an opening for such disagreements, honesty
              compels me to note that it's actually not impossible, just verbose.
              In regex notation, what you want is

              (list3* ((list1 (list1 | list3)*) | (list2 (list2 | list3)*))?)

              that is: any number of list3 elements, followed optionally by a mixed
              list of list1 and list3, or by a mixed list of list2 and list3. In
              XML Schema terms:

              <xsd:complexTyp e name="LISTtype" >
              <xsd:annotation ><xsd:documenta tion>
              <div xmlns="http://www.w3.org/1999/xhtml">
              <p>A content model which allows any number of either LIST1 or
              LIST2 elements, together with any number of LIST3 elements, in
              any order.</p>
              <p>The problem with this model is that it is intended to convey
              the idea that "order doesn't matter" but will, by allowing
              different orderings of the same material, inevitably lead some
              users and some programmers to believe that there may be
              meaningful differences in meaning based on order.
              </p>
              </div></xsd:documentati on></xsd:annotation>
              <xsd:sequence >
              <xsd:element ref="LIST3" minOccurs="0" maxOccurs="unbo unded"/>
              <xsd:choice minOccurs="0">
              <xsd:sequence >
              <xsd:element ref="LIST1"/>
              <xsd:choice minOccurs="0" maxOccurs="unbo unded">
              <xsd:element ref="LIST1"/>
              <xsd:element ref="LIST3"/>
              </xsd:choice>
              </xsd:sequence>
              <xsd:sequence >
              <xsd:element ref="LIST2"/>
              <xsd:choice minOccurs="0" maxOccurs="unbo unded">
              <xsd:element ref="LIST2"/>
              <xsd:element ref="LIST3"/>
              </xsd:choice>
              </xsd:sequence>
              </xsd:choice>
              </xsd:sequence>
              </xsd:complexType >

              The basic idea is that the instances of this content model will
              inevitably be either mixtures of LIST1 and LIST3, or of LIST2 and
              LIST3, or just sequences of LIST3. As long as you are just getting
              LIST3 elements, you can't tell which of these three possibilities is
              being realized. Once you see a LIST1 or a LIST2, however, you know
              which path to take through the regular expression and the other kind
              of list is no longer an option. Some people have said this
              content-model pattern reminds them of a harpoon: once the barb is in,
              the harpoon only goes one direction.

              The more restrictive alternative is somewhat simpler:

              <xsd:complexTyp e name="simplerLI STtype">
              <xsd:annotation ><xsd:documenta tion>
              <div xmlns="http://www.w3.org/1999/xhtml">
              <p>A simpler content model which prescribes an order and thus
              makes it impossible for variations in the order of elements
              to exist, let alone carry information.
              </p>
              <p>The only problem with this model is that some users will wish
              to convey subtle shades of meaning by putting the elements in
              different orders. The biggest virtue of this model is that it
              makes such behavior impossible. (If the shades of meaning are
              documented, they are worth having; otherwise, they are an
              illusion and only lead to tears down the road.)
              </p>
              </div></xsd:documentati on></xsd:annotation>
              <xsd:sequence >
              <xsd:choice minOccurs="0">
              <xsd:element ref="LIST1" maxOccurs="unbo unded"/>
              <xsd:element ref="LIST2" maxOccurs="unbo unded"/>
              </xsd:choice>
              <xsd:element ref="LIST3" minOccurs="0" maxOccurs="unbo unded"/>
              </xsd:sequence>
              </xsd:complexType >

              I hope this helps.

              -C. M. Sperberg-McQueen


              Comment

              • Gili Korman

                #8
                Re: Help needed with complex schema definition

                That was a really great help. I had to use the first solution as my
                requirements were to allow all orders...
                Thanks a lot!

                Comment

                Working...