Help needed with complex schema definition

Discussion in 'XML' started by Gili Korman, Sep 24, 2003.

  1. Gili Korman

    Gili Korman Guest

    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:complexType name="ListType">
    <xs:sequence>
    <xs:choice minOccurs="0">
    <xs:element name="ITEM1" type="ITEM1Type" minOccurs="0"
    maxOccurs="unbounded"/>
    <xs:element name="ITEM2" type="ITEM2Type" minOccurs="0"
    maxOccurs="unbounded"/>
    </xs:choice>
    <xs:element name="ITEM3" type="ITEM3Type" minOccurs="0"
    maxOccurs="unbounded"/>
    </xs:complexType>

    Any ideas?

    Thanks in advance,

    Gili Korman
    ITG
     
    Gili Korman, Sep 24, 2003
    #1
    1. Advertising

  2. Gili Korman wrote:

    > 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:


    How about

    <xs:element name="list">
    <xs:complexType>
    <xs:sequence minOccurs="0" maxOccurs="unbounded">
    <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

    http://www.atmedia.net/KlausRusch/
     
    Klaus Johannes Rusch, Sep 24, 2003
    #2
    1. Advertising

  3. Gili Korman

    Eric Sirois Guest

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

    <xs:complexType name="ListType">
    <xs:choice minOccurs="0" maxOccurs="unbounded">
    <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:
    > 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:complexType name="ListType">
    > <xs:sequence>
    > <xs:choice minOccurs="0">
    > <xs:element name="ITEM1" type="ITEM1Type" minOccurs="0"
    > maxOccurs="unbounded"/>
    > <xs:element name="ITEM2" type="ITEM2Type" minOccurs="0"
    > maxOccurs="unbounded"/>
    > </xs:choice>
    > <xs:element name="ITEM3" type="ITEM3Type" minOccurs="0"
    > maxOccurs="unbounded"/>
    > </xs:complexType>
    >
    > Any ideas?
    >
    > Thanks in advance,
    >
    > Gili Korman
    > ITG
     
    Eric Sirois, Sep 24, 2003
    #3
  4. (Gili Korman) writes:

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


    I'm not sure what this is trying to say. Can you try again?

    > The problem is that within the LIST item, the order of the elements
    > does not matter!


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

    > Any ideas?


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

    -C. M. Sperberg-McQueen
    World Wide Web Consortium
     
    C. M. Sperberg-McQueen, Sep 24, 2003
    #4
  5. Gili Korman

    Gili Korman Guest

    (C. M. Sperberg-McQueen) wrote in message news:<>...
    > (Gili Korman) writes:
    >
    > > 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>

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

    >
    > 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.)
    >
    > > Any ideas?

    >
    > Not until I understand better what it is you're trying to do.
    >
    > -C. M. Sperberg-McQueen
    > World Wide Web Consortium



    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...
     
    Gili Korman, Sep 25, 2003
    #5
  6. Gili Korman

    Gili Korman Guest

    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 !
     
    Gili Korman, Sep 25, 2003
    #6
  7. (Gili Korman) writes:

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


    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:complexType name="LISTtype">
    <xsd:annotation><xsd:documentation>
    <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:documentation></xsd:annotation>
    <xsd:sequence>
    <xsd:element ref="LIST3" minOccurs="0" maxOccurs="unbounded"/>
    <xsd:choice minOccurs="0">
    <xsd:sequence>
    <xsd:element ref="LIST1"/>
    <xsd:choice minOccurs="0" maxOccurs="unbounded">
    <xsd:element ref="LIST1"/>
    <xsd:element ref="LIST3"/>
    </xsd:choice>
    </xsd:sequence>
    <xsd:sequence>
    <xsd:element ref="LIST2"/>
    <xsd:choice minOccurs="0" maxOccurs="unbounded">
    <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:complexType name="simplerLISTtype">
    <xsd:annotation><xsd:documentation>
    <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:documentation></xsd:annotation>
    <xsd:sequence>
    <xsd:choice minOccurs="0">
    <xsd:element ref="LIST1" maxOccurs="unbounded"/>
    <xsd:element ref="LIST2" maxOccurs="unbounded"/>
    </xsd:choice>
    <xsd:element ref="LIST3" minOccurs="0" maxOccurs="unbounded"/>
    </xsd:sequence>
    </xsd:complexType>

    I hope this helps.

    -C. M. Sperberg-McQueen
     
    C. M. Sperberg-McQueen, Sep 26, 2003
    #7
  8. Gili Korman

    Gili Korman Guest

    That was a really great help. I had to use the first solution as my
    requirements were to allow all orders...
    Thanks a lot!
     
    Gili Korman, Sep 29, 2003
    #8
    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,622
    Markus
    Nov 23, 2005
  2. Abhinav
    Replies:
    6
    Views:
    1,113
    Abhinav
    Aug 16, 2004
  3. Stanimir Stamenkov
    Replies:
    3
    Views:
    1,301
    Stanimir Stamenkov
    Apr 25, 2005
  4. Stanimir Stamenkov
    Replies:
    2
    Views:
    767
    Stanimir Stamenkov
    Oct 25, 2005
  5. Ark
    Replies:
    1
    Views:
    439
    Chris Torek
    Aug 7, 2004
Loading...

Share This Page