Elements with maxOccurs (some unbound, some 1)

Discussion in 'XML' started by foolproofplan@gmail.com, May 22, 2007.

  1. Guest

    Maybe I am looking to far into a simple problem, but I am having quite
    a hard time figuring this out:

    I am currently trying to create a schema to represent an Element which
    contains other Elements (some of which have a restriction on how many
    can occur). Here is an example of what I have done if that seems

    <xsd:element name="Object">
    <xsd:choice maxOccurs="unbounded">
    <xsd:element ref="License" minOccurs="0"/>
    <xsd:element ref="NameMemberReference" minOccurs="0"
    <xsd:element ref="ParentMemberReference" minOccurs="0"
    <xsd:element ref="Members"/>
    <xsd:element ref="OnEdit" minOccurs="0"/>
    <xsd:element ref="OnCommit" minOccurs="0"/>
    <xsd:element ref="Permissions" minOccurs="0"/>
    <xsd:attribute ref="name" use="required"/>

    I think the trouble with this is that the two elements that need to be
    restricted to one occurance (NameMememberReference and
    ParentMemberReference) are within an unbounded choice so they still
    can be created multiple times.

    I've played around with some other idea by using a Choice and an All
    and I've also trying making groups but nothing has seemed to solve my
    problem. Any ideas?

    - Marc
    , May 22, 2007
    1. Advertisements

  2. wrote:
    > Any ideas

    Do you really need to leave the order unconstrained? If you're willing
    to nail down the order slightly, factor the two maxOccurs='1' items out
    and enclose them and the choice in a sequence.

    Or make the whole thing a sequence and just require folks to give the
    contents in that specific order, if there isn't a good reason to let
    them randomly intermix the contents.

    Joe Kesselman / Beware the fury of a patient man. -- John Dryden
    Joseph Kesselman, May 22, 2007
    1. Advertisements

  3. Guest

    Joseph Kesselman <> wrote:
    > Do you really need to leave the order unconstrained?

    Yep, the order is going to have to be left open. It's something beyond
    my control.
    , May 23, 2007
  4. If it was just a single constrained element, I'd suggest breaking it up
    into submodels -- any mixture of the others, that one, any mixture of
    the others.

    With two, and being unwilling to constrain their order... I think you
    can do it by combining that idea with Martin's solution in the thread
    entitled "Xml Schema OR, XOR", breaking things down into non-redundant
    cases. But you're going to wind up with a lot of copy-and-repeat Schema
    code to express that.

    There may be a better solution; my schema skills aren't supurb.

    There's always the alternative of applying the at-most-one constraint in
    applications (semantic validation) rather than in schemas (higher-level
    syntactic validation).

    Joe Kesselman / Beware the fury of a patient man. -- John Dryden
    Joseph Kesselman, May 23, 2007
    1. Advertisements

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
    Jun 1, 2006
  2. mavis
    Jun 1, 2006
  3. Replies:
    Joe Kesselman
    Jun 5, 2006
  4. Replies:
    Boris Kolpackov
    May 23, 2007
  5. Replies:
    Boris Kolpackov
    May 24, 2007

Share This Page