Re: Elements with maxOccurs (some unbound, some 1)

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

  1. Guest

    With Joe's help, and a little searching of my own, I have found a
    solution.
    It involves creating multiple extended ComplexTypes with a base.

    I figured posting it wouldn't hurt:

    <xsd:complexType name="OneNameMemRef">
    <xsd:choice maxOccurs="1">
    <xsd:element ref="NameMemberReference" minOccurs="0"
    maxOccurs="1"/>
    </xsd:choice>
    </xsd:complexType>

    <xsd:complexType name="OneNameAndParentMemRef">
    <xsd:complexContent>
    <xsd:extension base="OneNameMemRef">
    <xsd:choice maxOccurs="1">
    <xsd:element ref="ParentMemberReference" minOccurs="0"
    maxOccurs="1"/>
    </xsd:choice>
    </xsd:extension>
    </xsd:complexContent>
    </xsd:complexType>

    <xsd:element name="ObjectTemplate">
    <xsd:complexType>
    <xsd:complexContent>
    <xsd:extension base="OneNameAndParentMemRef">
    <xsd:choice maxOccurs="unbounded">
    <xsd:element ref="License" minOccurs="0"/>
    <xsd:element ref="OnEdit" minOccurs="0"/>
    <xsd:element ref="OnCommit" minOccurs="0"/>
    <xsd:element ref="Members" minOccurs="0"/>
    <xsd:element ref="Permissions" minOccurs="0"/>
    </xsd:choice>
    <xsd:attribute ref="name" use="required"/>
    </xsd:extension>
    </xsd:complexContent>
    </xsd:complexType>
    </xsd:element>
     
    , May 23, 2007
    #1
    1. Advertising

  2. wrote:
    > It involves creating multiple extended ComplexTypes with a base.


    Interesting use of type complex extension; that hadn't occurred to me,
    but it does sorta make sense. Well done; I'm going to have to remember
    that trick.

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

  3. writes:

    > With Joe's help, and a little searching of my own, I have found a
    > solution. It involves creating multiple extended ComplexTypes with
    > a base.


    When you inherit-by-extension one complex type from another, the
    effective content model is a concatenation of individual content
    models with the sequence compositor. You schema is equivalent to
    the following:

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

    Which means that NameMemberReference has to come first, ParentMemberReference
    second and the rest can come after the two in any order.


    hth,
    -boris


    --
    Boris Kolpackov
    Code Synthesis Tools CC
    http://www.codesynthesis.com
    Open-Source, Cross-Platform C++ XML Data Binding
     
    Boris Kolpackov, May 23, 2007
    #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:
    450
    Mavis
    Jun 1, 2006
  2. mavis
    Replies:
    2
    Views:
    3,809
    mavis
    Jun 1, 2006
  3. Replies:
    2
    Views:
    2,184
    Joe Kesselman
    Jun 5, 2006
  4. Replies:
    3
    Views:
    441
    Joseph Kesselman
    May 23, 2007
  5. Replies:
    1
    Views:
    446
    Boris Kolpackov
    May 24, 2007
Loading...

Share This Page