Schema: restrict occurences but not order

Discussion in 'XML' started by thierry, Jun 17, 2009.

  1. thierry

    thierry Guest

    Hi,

    I am trying to do something apparently simple but I cannot succeed.
    I try to write a schema for an element containing several children
    in any order but I want to restrict the number of occurrences of
    each children.

    This would be something like that, without the ordering which is
    imposed by xs:sequence:

    <xs:element name="root">
    <xs:complexType>
    <xs:sequence>
    <xs:element name="a" minOccurs="0" maxOccurs="unbounded" />
    <xs:element name="b" minOccurs="1" maxOccurs="unbounded" />
    <xs:element name="c" minOccurs="1" maxOccurs="1" />
    </xs:sequence>
    </xs:complexType>
    </xs:element>

    For instance, the following should pass:

    <root> <b/> <c/> <b/> <a/> </root>

    But the following should not (two many <c/>):

    <root> <b/> <c/> <b/> <c/> </root>

    I tried several combinations using xs:all or xs:choice but I either
    fail to restrict the number of occurences or fail to allow any order.

    Your help will be greatly appreciated.

    <thierry/>
     
    thierry, Jun 17, 2009
    #1
    1. Advertising

  2. Not possible in XML Schema unless you spell out all the possible
    alternative sequences, which rapidly becomes hugely verbose for any but
    the simplest cases. Generally folks don't try to implement this kind of
    restriction in their schemas, but instead handle it in application
    code and/or user documentation.

    (SGML had a simple way to express this pattern. XML deliberately dropped
    that because it's a Royal Pain to implement correctly, requiring some
    nonstandard parser/grammar technology.)
     
    Joe Kesselman, Jun 18, 2009
    #2
    1. Advertising

  3. thierry

    thierry Guest

    Joe Kesselman wrote :
    > Not possible in XML Schema unless you spell out all the possible
    > alternative sequences, which rapidly becomes hugely verbose for any but
    > the simplest cases. Generally folks don't try to implement this kind of
    > restriction in their schemas, but instead handle it in application code
    > and/or user documentation.


    Too bad... Thanks for your help. Will check the number of occurences in the
    application.
     
    thierry, Jun 18, 2009
    #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. Markus
    Replies:
    1
    Views:
    1,661
    Markus
    Nov 23, 2005
  2. Piers Chivers
    Replies:
    0
    Views:
    528
    Piers Chivers
    Feb 18, 2004
  3. John Jørgensen

    XML schema: duplicate element occurences

    John Jørgensen, Jul 7, 2004, in forum: XML
    Replies:
    2
    Views:
    1,153
    John Jørgensen
    Jul 9, 2004
  4. Stanimir Stamenkov
    Replies:
    3
    Views:
    1,325
    Stanimir Stamenkov
    Apr 25, 2005
  5. Christoph Krammer

    re.sub does not replace all occurences

    Christoph Krammer, Aug 7, 2007, in forum: Python
    Replies:
    3
    Views:
    553
    Christoph Krammer
    Aug 7, 2007
Loading...

Share This Page