XSD: complexType with mandatory and optional elements in arbitraryorder?

Discussion in 'XML' started by Thomas Wittek, Sep 12, 2007.

  1. Hi!

    Is it possible to define a complexType that contains
    * some elements exactly one time
    * some other elements 0 or 1 times and
    * some additional elements 0 to * times
    -- where all elements may occur in arbitrary order?

    First, I thought of xs:all, but maxOccurs cannot be greater than 1.
    With xs:sequence and xs:choice I could define sub sequences with min/max
    = 1/1, 0/1 and 0/* -- but I don't want to restrict the order.

    Basically, I'm looking for xs:all with maxOccurs="unbounded" for some
    elements.
    Can you express this behavior with other definitions?

    Thank you!
    --
    Thomas Wittek
    Web: http://gedankenkonstrukt.de/
    Jabber: -pobox.net
    GPG: 0xF534E231
     
    Thomas Wittek, Sep 12, 2007
    #1
    1. Advertising

  2. Thomas Wittek wrote:
    > Is it possible to define a complexType that contains
    > * some elements exactly one time
    > * some other elements 0 or 1 times and
    > * some additional elements 0 to * times
    > -- where all elements may occur in arbitrary order?


    Possible, yes. Pleasant, no; you will probably have to spell out all the
    possible orders. This is one place where some of the other,
    not-officially-blessed, schema languages have advantages.

    The simplest solution while staying within XSD is to restrict the order.
    If you've got this complicated a data structure, it's generally going to
    be machine-generated anyway so leaving the order flexible doesn't buy
    you much. And even humans can eventually be taught to follow directions,
    if you're patient enough.

    Second simplest solution is to remove the number-of-instances
    constraints from the schema and implement them in the application.

    --
    () ASCII Ribbon Campaign | Joe Kesselman
    /\ Stamp out HTML e-mail! | System architexture and kinetic poetry
     
    Joe Kesselman, Sep 13, 2007
    #2
    1. Advertising

  3. Joe Kesselman:
    > Thomas Wittek wrote:
    >> Is it possible to define a complexType that contains
    >> * some elements exactly one time
    >> * some other elements 0 or 1 times and
    >> * some additional elements 0 to * times
    >> -- where all elements may occur in arbitrary order?

    >
    > Possible, yes. Pleasant, no; you will probably have to spell out all the
    > possible orders. This is one place where some of the other,
    > not-officially-blessed, schema languages have advantages.


    You've got it ;) Actually, I'm writing an extension to Atom, which is
    specified in Relax NG and "assigns no significance to the order of
    appearance of the child elements".
    So I also wanted to allow arbitrary order within my extension.

    As I also still didn't find an Atom XSD (that cannot exist due to the
    lack of the missing "interleave" mode in XSD), I should probably try to
    write my extension in RNG.

    > The simplest solution while staying within XSD is to restrict the order.


    That would be the solution of choice, if I'd stick to XSD, as I want to
    do the validation with the schema and not within the application.

    Thank you for the insights!
    --
    Thomas Wittek
    Web: http://gedankenkonstrukt.de/
    Jabber: -pobox.net
    GPG: 0xF534E231
     
    Thomas Wittek, Sep 13, 2007
    #3
  4. Thomas Wittek

    George Bina Guest

    Re: XSD: complexType with mandatory and optional elements in arbitrary order?

    Just a note regarding "some of the other, not-officially-blessed,
    schema languages have advantages": all NVDL, Relax NG and Schematron
    are ISO standards.

    Note that you can also have XML Schema with embedded Schematron rules.
    You specify a more relaxed model in the XML Schema and add the
    remaining restrictions in the embedded Schematron rules.

    As you mentioned Atom extensions you may find useful also the
    following recent announcement from MURATA Makoto:
    http://lists.dsdl.org/dsdl-comment/2007-09/0003.html
    NVDL is the simplest approach to that. More, it allows you to combine
    Relax NG, XML Schema and Schematron.

    Regards,
    George
    ---------------------------------------------------------------------
    George Cristian Bina - http://aboutxml.blogspot.com/
    <oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
    http://www.oxygenxml.com
     
    George Bina, Sep 13, 2007
    #4
  5. George Bina wrote:
    > Just a note regarding "some of the other, not-officially-blessed,
    > schema languages have advantages": all NVDL, Relax NG and Schematron
    > are ISO standards.


    Thanks for the correction; I knew they were headed in that direction but...

    Of course "standard" in a rapidly-evolving environment like XML is a
    misleading term, which is why the W3C explicitly doesn't use it,
    preferring to call things "recommendations" until they've survived
    extensive contact with the real world and are pretty clearly in final form.

    My personal preference is to stick with a pure W3C solution as long as I
    can, since that tends to be most widely supported and most carefully
    checked for interactions with other W3C work. But I freely admit that
    I'm biased, having worked on one of the recommendations.

    --
    () ASCII Ribbon Campaign | Joe Kesselman
    /\ Stamp out HTML e-mail! | System architexture and kinetic poetry
     
    Joe Kesselman, Sep 13, 2007
    #5
    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. Piers Chivers
    Replies:
    2
    Views:
    410
    Piers Chivers
    Mar 2, 2004
  2. unishippers.suckfeed.newshosting.com

    XSD Schema: complexType or Group?

    unishippers.suckfeed.newshosting.com, Nov 4, 2004, in forum: XML
    Replies:
    2
    Views:
    416
    unishippers.suckfeed.newshosting.com
    Nov 5, 2004
  3. MENTAT
    Replies:
    8
    Views:
    1,002
    MENTAT
    Apr 4, 2005
  4. ANoobee
    Replies:
    3
    Views:
    403
  5. byrnejb
    Replies:
    0
    Views:
    113
    byrnejb
    Jul 15, 2010
Loading...

Share This Page