sequence inside a choice

Discussion in 'XML' started by Ryan, Jun 19, 2008.

  1. Ryan

    Ryan Guest

    Is it legal to have something like:
    <xs:complexType name="transaction">
    <xs:choice minOccurs="1" maxOccurs="unbounded">
    <xs:sequence minOccurs="1" maxOccurs="unbounded">
    <xs:element name="account_login"
    type="login_data" minOccurs="0" maxOccurs="unbounded" />
    <xs:element name="create_id"
    type="tbl_iv" minOccurs="0" maxOccurs="unbounded" />
    <xs:element name="org_create"
    type="org" minOccurs="0" maxOccurs="unbounded" />
    </xs:sequence>
    </xs:choice>
    </xs:complexType>

    Notice how there is a sequence inside a choice and nothing else.

    Also, what do the minOccurs/maxOccurs modifiers do on the choice and
    sequence grouping?
     
    Ryan, Jun 19, 2008
    #1
    1. Advertising

  2. Ryan wrote:
    > Is it legal to have something like:
    > <xs:complexType name="transaction">
    > <xs:choice minOccurs="1" maxOccurs="unbounded">
    > <xs:sequence minOccurs="1" maxOccurs="unbounded">
    > <xs:element name="account_login"
    > type="login_data" minOccurs="0" maxOccurs="unbounded" />
    > <xs:element name="create_id"
    > type="tbl_iv" minOccurs="0" maxOccurs="unbounded" />
    > <xs:element name="org_create"
    > type="org" minOccurs="0" maxOccurs="unbounded" />
    > </xs:sequence>
    > </xs:choice>
    > </xs:complexType>
    >
    > Notice how there is a sequence inside a choice and nothing else.


    I think that is allowed but you can check yourself with a schema
    validator like http://www.w3.org/2001/03/webdata/xsv
    It is a different question whether it makes much sense and can not be
    simplified, it seems to me that the above can be simplified to simply
    put the sequence directly into the complexType.

    > Also, what do the minOccurs/maxOccurs modifiers do on the choice and
    > sequence grouping?


    Saying that the whole choice or sequence can occur as often as the
    maxOccurs specifies so unbounded or exactly once as the minOccurs="1"
    specifies.


    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
     
    Martin Honnen, Jun 19, 2008
    #2
    1. Advertising

  3. Ryan

    Ryan Guest

    On Jun 19, 11:28 am, Martin Honnen <> wrote:
    > Ryan wrote:
    > > Is it legal to have something like:
    > > <xs:complexType name="transaction">
    > > <xs:choice minOccurs="1" maxOccurs="unbounded">
    > > <xs:sequence minOccurs="1" maxOccurs="unbounded">
    > > <xs:element name="account_login"
    > > type="login_data" minOccurs="0" maxOccurs="unbounded" />
    > > <xs:element name="create_id"
    > > type="tbl_iv" minOccurs="0" maxOccurs="unbounded" />
    > > <xs:element name="org_create"
    > > type="org" minOccurs="0" maxOccurs="unbounded" />
    > > </xs:sequence>
    > > </xs:choice>
    > > </xs:complexType>

    >
    > > Notice how there is a sequence inside a choice and nothing else.

    >
    > I think that is allowed but you can check yourself with a schema
    > validator likehttp://www.w3.org/2001/03/webdata/xsv
    > It is a different question whether it makes much sense and can not be
    > simplified, it seems to me that the above can be simplified to simply
    > put the sequence directly into the complexType.
    >
    > > Also, what do the minOccurs/maxOccurs modifiers do on the choice and
    > > sequence grouping?

    >
    > Saying that the whole choice or sequence can occur as often as the
    > maxOccurs specifies so unbounded or exactly once as the minOccurs="1"
    > specifies.
    >
    > --
    >
    > Martin Honnen
    > http://JavaScript.FAQTs.com/


    So, according to the original xsd, would this be valid:

    <transaction>
    <account_login>data</account_login>
    <org_create>data</org_create>
    <org_create>data</org_create>
    <create_id>data</create_id>
    <org_create>data</org_create>
    </transaction>

    Stipulating that data is valid data inside the pairs.
     
    Ryan, Jun 19, 2008
    #3
  4. Ryan wrote:

    > So, according to the original xsd, would this be valid:
    >
    > <transaction>


    The original xsd you posted only defined a complexType named
    transaction, not an element of that name.
    If you define

    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:element name="transaction" type="transaction"/>
    <xs:complexType name="transaction">
    <xs:choice minOccurs="1" maxOccurs="unbounded">
    <xs:sequence minOccurs="1" maxOccurs="unbounded">
    <xs:element name="account_login"
    type="xs:string" minOccurs="0" maxOccurs="unbounded" />
    <xs:element name="create_id"
    type="xs:string" minOccurs="0" maxOccurs="unbounded" />
    <xs:element name="org_create"
    type="xs:string" minOccurs="0" maxOccurs="unbounded" />
    </xs:sequence>
    </xs:choice>
    </xs:complexType>
    </xs:schema>

    then I think your sample is valid.


    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
     
    Martin Honnen, Jun 20, 2008
    #4
  5. Ryan

    Ryan Guest

    From your comments it sounds to me that if you have
    <xs:choice minOccurs="1" maxOccurs="unbounded"><xs:sequence
    minOccurs="1" maxOccurs="unbounded">
    <!-- elements -->
    </xs:sequence></xs:choice>

    That the outer choice is ignored. Is this accurate?

    -Ryan

    On Jun 20, 4:57 am, Martin Honnen <> wrote:
    > Ryan wrote:
    > > So, according to the original xsd, would this be valid:

    >
    > > <transaction>

    >
    > The original xsd you posted only defined a complexType named
    > transaction, not an element of that name.
    > If you define
    >
    > <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
    > <xs:element name="transaction" type="transaction"/>
    > <xs:complexType name="transaction">
    > <xs:choice minOccurs="1" maxOccurs="unbounded">
    > <xs:sequence minOccurs="1" maxOccurs="unbounded">
    > <xs:element name="account_login"
    > type="xs:string" minOccurs="0" maxOccurs="unbounded" />
    > <xs:element name="create_id"
    > type="xs:string" minOccurs="0" maxOccurs="unbounded" />
    > <xs:element name="org_create"
    > type="xs:string" minOccurs="0" maxOccurs="unbounded" />
    > </xs:sequence>
    > </xs:choice>
    > </xs:complexType>
    > </xs:schema>
    >
    > then I think your sample is valid.
    >
    > --
    >
    > Martin Honnen
    > http://JavaScript.FAQTs.com/
     
    Ryan, Jun 20, 2008
    #5
  6. Ryan wrote:
    > From your comments it sounds to me that if you have
    > <xs:choice minOccurs="1" maxOccurs="unbounded"><xs:sequence
    > minOccurs="1" maxOccurs="unbounded">
    > <!-- elements -->
    > </xs:sequence></xs:choice>
    >
    > That the outer choice is ignored. Is this accurate?


    I don't think it is ignored by the schema parser or the validator. But
    it looks to me as if you could simplify the structure if you want to.


    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
     
    Martin Honnen, Jun 20, 2008
    #6
    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. Mickey Segal
    Replies:
    0
    Views:
    946
    Mickey Segal
    Feb 2, 2004
  2. zorro
    Replies:
    0
    Views:
    456
    zorro
    Jul 31, 2004
  3. melograno
    Replies:
    3
    Views:
    472
    Arthur
    Apr 29, 2005
  4. miles.jg
    Replies:
    16
    Views:
    925
    Alf P. Steinbach
    Nov 14, 2007
  5. Stefano Crocco
    Replies:
    4
    Views:
    162
    Rados³aw Bu³at
    Feb 5, 2009
Loading...

Share This Page