<xs:all> with unbounded elements

Discussion in 'XML' started by nosferatu_1_1@yahoo.com, Feb 23, 2005.

  1. Guest

    Hi,

    I would like to create a schema that validate the following xml:

    <music>
    <pop/>
    <rock/>
    <pop/>
    </music>

    that is, <rock> should only appear once while <pop> can appear several
    times. In addition, <pop> and <rock> elements can appear in any order.

    I would propose the following (invalid) schema:

    <xs:element name="music">
    <xs:complexType>
    <xs:all>
    <xs:element name="rock"/>
    <xs:element name="pop" maxOccurs="unbounded"/>
    </xs:all>
    </xs:complexType>
    </xs:element>

    This schema is invalid because the constraint maxOccurs within <xs:all>
    cannot be greater that 1. (Nevertheless it represents what I'm looking
    for)

    It seems that neither <xs:all> nor <xs:sequence> nor <xs:choice> gives
    this possibility. So my question is: is there another way of defining
    such a behaviour with a schema ?

    I tried to generate the schema with XMLSpy but it gave me something
    like:

    <xs:element name="music">
    <xs:complexType>
    <xs:sequence>
    <xs:element name="pop"/>
    <xs:element name="rock"/>
    <xs:element name="pop"/>
    </xs:sequence>
    </xs:complexType>
    </xs:element>

    Which is not really usefull since I don't know in advance the number of
    <pop> elements.

    Thanks
    , Feb 23, 2005
    #1
    1. Advertising

  2. that is, <rock> should only appear once while <pop> can appear several
    times. In addition, <pop> and <rock> elements can appear in any order.

    in dtd syntax you need

    (rock,pop*)|(pop+,rock,pop*)

    It should be easy enough to translate that back to xsd syntax.

    David
    David Carlisle, Feb 23, 2005
    #2
    1. Advertising

  3. Guest

    The problem is that if I add new elements like <metal>, <soul>, etc...
    the syntax you propose becomes too complex to define. My real-life
    problem has about 20 different elements.
    And the translation to xsd gives a solution with similar complexity.
    , Feb 23, 2005
    #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. Mavis
    Replies:
    0
    Views:
    430
    Mavis
    Jun 1, 2006
  2. mavis
    Replies:
    2
    Views:
    3,715
    mavis
    Jun 1, 2006
  3. Maheshkumar.R

    How to skip the unbounded column...? new bie

    Maheshkumar.R, Jun 15, 2005, in forum: ASP .Net Datagrid Control
    Replies:
    1
    Views:
    118
    Kim Quigley
    Jun 16, 2005
  4. Fabiano

    Unbounded Datagrid

    Fabiano, May 5, 2004, in forum: ASP .Net Web Controls
    Replies:
    3
    Views:
    114
    Steven Cheng[MSFT]
    May 11, 2004
  5. John Harvey
    Replies:
    0
    Views:
    151
    John Harvey
    Jan 9, 2006
Loading...

Share This Page