a set of elements occur in any order with multiple occurrences

Discussion in 'XML' started by mavis, Oct 10, 2006.

  1. mavis

    mavis Guest

    Could you please help me with this xsd definition?

    I need to define a set of elements occur in any order with multiple
    occurrences, but the same kind of elements need to group together...

    Sth like this....

    <xs:element name="A">
    <xs:complexType>
    <xs:all>

    <xs:element name="B-1" type="xs:string" minOccurs="0"
    maxOccurs="unbounded"/>

    <xs:element name="B-2" type="xs:string" minOccurs="0"
    maxOccurs="unbounded"/>

    <xs:element name="B-3" type="xs:string" minOccurs="0"
    maxOccurs="unbounded"/>

    <xs:element name="B-4" type="xs:string" minOccurs="0"
    maxOccurs="unbounded"/>

    </xs:all>

    </xs:complexType>
    </xs:element>

    The above definition cannot be validated correctly...

    Thanks in advance!

    Mavis
    mavis, Oct 10, 2006
    #1
    1. Advertising

  2. mavis

    George Bina Guest

    Hi,

    xs:all has a number of limitations in XML Schema. The closest you can
    get with XML schema alone is to specify a 0 to 4 choice of the same
    content that you have in xs:all. The full checking can be done either
    at application level or using a Schematron rule embedded in the XML
    Schema, sull working sample below:

    <?xml version="1.0" encoding="UTF-8"?>
    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:element name="A">
    <xs:complexType>
    <xs:annotation>
    <xs:appinfo>
    <pattern xmlns="http://www.ascc.net/xml/schematron"
    name="testGrouping">
    <rule context="A">
    <assert
    test="not(B-1[following-sibling::*[not(self::B-1)][following-sibling::B-1]])">
    B-1 elements should stay together. </assert>
    <assert
    test="not(B-2[following-sibling::*[not(self::B-2)][following-sibling::B-2]])">
    B-2 elements should stay together. </assert>
    <assert
    test="not(B-3[following-sibling::*[not(self::B-3)][following-sibling::B-3]])">
    B-3 elements should stay together. </assert>
    <assert
    test="not(B-4[following-sibling::*[not(self::B-4)][following-sibling::B-4]])">
    B-4 elements should stay together. </assert>
    </rule>
    </pattern>
    </xs:appinfo>
    </xs:annotation>
    <xs:choice maxOccurs="4">
    <xs:element name="B-1" type="xs:string" minOccurs="0"
    maxOccurs="unbounded"/>
    <xs:element name="B-2" type="xs:string" minOccurs="0"
    maxOccurs="unbounded"/>
    <xs:element name="B-3" type="xs:string" minOccurs="0"
    maxOccurs="unbounded"/>
    <xs:element name="B-4" type="xs:string" minOccurs="0"
    maxOccurs="unbounded"/>
    </xs:choice>
    </xs:complexType>
    </xs:element>
    </xs:schema>

    Basically each assert test not to have an element followed by an
    element different than it and then that followed by an element with the
    same name as the initial one.

    Best Regards,
    George
    ---------------------------------------------------------------------
    George Cristian Bina
    <oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
    http://www.oxygenxml.com


    mavis wrote:
    > Could you please help me with this xsd definition?
    >
    > I need to define a set of elements occur in any order with multiple
    > occurrences, but the same kind of elements need to group together...
    >
    > Sth like this....
    >
    > <xs:element name="A">
    > <xs:complexType>
    > <xs:all>
    >
    > <xs:element name="B-1" type="xs:string" minOccurs="0"
    > maxOccurs="unbounded"/>
    >
    > <xs:element name="B-2" type="xs:string" minOccurs="0"
    > maxOccurs="unbounded"/>
    >
    > <xs:element name="B-3" type="xs:string" minOccurs="0"
    > maxOccurs="unbounded"/>
    >
    > <xs:element name="B-4" type="xs:string" minOccurs="0"
    > maxOccurs="unbounded"/>
    >
    > </xs:all>
    >
    > </xs:complexType>
    > </xs:element>
    >
    > The above definition cannot be validated correctly...
    >
    > Thanks in advance!
    >
    > Mavis
    George Bina, Oct 11, 2006
    #2
    1. Advertising

  3. mavis

    mavis Guest

    Thanks a lot!!!

    -M


    George Bina wrote:
    > Hi,
    >
    > xs:all has a number of limitations in XML Schema. The closest you can
    > get with XML schema alone is to specify a 0 to 4 choice of the same
    > content that you have in xs:all. The full checking can be done either
    > at application level or using a Schematron rule embedded in the XML
    > Schema, sull working sample below:
    >
    > <?xml version="1.0" encoding="UTF-8"?>
    > <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
    > <xs:element name="A">
    > <xs:complexType>
    > <xs:annotation>
    > <xs:appinfo>
    > <pattern xmlns="http://www.ascc.net/xml/schematron"
    > name="testGrouping">
    > <rule context="A">
    > <assert
    > test="not(B-1[following-sibling::*[not(self::B-1)][following-sibling::B-1]])">
    > B-1 elements should stay together. </assert>
    > <assert
    > test="not(B-2[following-sibling::*[not(self::B-2)][following-sibling::B-2]])">
    > B-2 elements should stay together. </assert>
    > <assert
    > test="not(B-3[following-sibling::*[not(self::B-3)][following-sibling::B-3]])">
    > B-3 elements should stay together. </assert>
    > <assert
    > test="not(B-4[following-sibling::*[not(self::B-4)][following-sibling::B-4]])">
    > B-4 elements should stay together. </assert>
    > </rule>
    > </pattern>
    > </xs:appinfo>
    > </xs:annotation>
    > <xs:choice maxOccurs="4">
    > <xs:element name="B-1" type="xs:string" minOccurs="0"
    > maxOccurs="unbounded"/>
    > <xs:element name="B-2" type="xs:string" minOccurs="0"
    > maxOccurs="unbounded"/>
    > <xs:element name="B-3" type="xs:string" minOccurs="0"
    > maxOccurs="unbounded"/>
    > <xs:element name="B-4" type="xs:string" minOccurs="0"
    > maxOccurs="unbounded"/>
    > </xs:choice>
    > </xs:complexType>
    > </xs:element>
    > </xs:schema>
    >
    > Basically each assert test not to have an element followed by an
    > element different than it and then that followed by an element with the
    > same name as the initial one.
    >
    > Best Regards,
    > George
    > ---------------------------------------------------------------------
    > George Cristian Bina
    > <oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
    > http://www.oxygenxml.com
    >
    >
    > mavis wrote:
    > > Could you please help me with this xsd definition?
    > >
    > > I need to define a set of elements occur in any order with multiple
    > > occurrences, but the same kind of elements need to group together...
    > >
    > > Sth like this....
    > >
    > > <xs:element name="A">
    > > <xs:complexType>
    > > <xs:all>
    > >
    > > <xs:element name="B-1" type="xs:string" minOccurs="0"
    > > maxOccurs="unbounded"/>
    > >
    > > <xs:element name="B-2" type="xs:string" minOccurs="0"
    > > maxOccurs="unbounded"/>
    > >
    > > <xs:element name="B-3" type="xs:string" minOccurs="0"
    > > maxOccurs="unbounded"/>
    > >
    > > <xs:element name="B-4" type="xs:string" minOccurs="0"
    > > maxOccurs="unbounded"/>
    > >
    > > </xs:all>
    > >
    > > </xs:complexType>
    > > </xs:element>
    > >
    > > The above definition cannot be validated correctly...
    > >
    > > Thanks in advance!
    > >
    > > Mavis
    mavis, Oct 11, 2006
    #3
    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. Miguel Dias Moura
    Replies:
    4
    Views:
    455
    Hans Kesting
    May 6, 2004
  2. Pete
    Replies:
    1
    Views:
    901
    Martin Honnen
    Nov 27, 2004
  3. Mike
    Replies:
    3
    Views:
    327
    Tim Chase
    May 4, 2006
  4. bahoo
    Replies:
    37
    Views:
    846
    Paul McGuire
    Apr 9, 2007
  5. pinkisntwell
    Replies:
    5
    Views:
    723
    Gabriel Genellina
    Nov 10, 2009
Loading...

Share This Page