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
    confusing:

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

    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?

    Thanks,
    - Marc
     
    , May 22, 2007
    #1
    1. Advertising

  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
    #2
    1. Advertising

  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
    #3
  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
    #4
    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:
    443
    Mavis
    Jun 1, 2006
  2. mavis
    Replies:
    2
    Views:
    3,767
    mavis
    Jun 1, 2006
  3. Replies:
    2
    Views:
    2,168
    Joe Kesselman
    Jun 5, 2006
  4. Replies:
    2
    Views:
    469
    Boris Kolpackov
    May 23, 2007
  5. Replies:
    1
    Views:
    439
    Boris Kolpackov
    May 24, 2007
Loading...

Share This Page