xs:choice and child elements with minOccurs=0

Discussion in 'XML' started by Peter Larsen, Jul 21, 2008.

  1. Peter Larsen

    Peter Larsen Guest

    Is this really a valid schema design?

    <?xml version="1.0" encoding="UTF-8"?>
    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
    elementFormDefault="qualified">
    <xs:element name="root">
    <xs:complexType>
    <xs:sequence>
    <xs:choice>
    <xs:element name="e1" minOccurs="0" />
    <xs:element name="e2" minOccurs="0"/>
    <xs:element name="e3" minOccurs="0"/>
    </xs:choice>
    </xs:sequence>
    </xs:complexType>
    </xs:element>
    </xs:schema>

    Doesn't the W3C specs say that xs:choice HAS to return at least one
    element? Maybe I'm interpreting the "element" a bit too specific here
    - because it even allows me to add maxOccurs="Unlimited" to a child of
    a choice and it allows me to repeat the element of that has the
    unlimited occurrence on it within the choice.

    If the above is valid - which I sorta doubt - is that because it's
    specifically NOT forbidden by the w3c specs (http://www.w3.org/TR/2001/
    REC-xmlschema-1-20010502)?

    My basic problem is that the modifiers on these particles violate the
    xs:choice rules. And that seems to be allowed? I've also noticed it
    just takes one of the child elements to have a minOccurs="0" to make
    the whole choice construct optional. Is there any difference if just
    one is "optional" versus all children of a xs:choice being optional?

    xerces 2.8 seems to validate the above schema just fine - and run it
    with data that (to me) violates the xs:choice. For instance, <root></
    root> is valid in the above example. If the choice needs to be
    optional why not simply use minOccurs="0" on the xs:choice element
    instead of it's children?
     
    Peter Larsen, Jul 21, 2008
    #1
    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:
    913
    Mickey Segal
    Feb 2, 2004
  2. Jeff Rodriguez
    Replies:
    23
    Views:
    1,157
    David Schwartz
    Dec 9, 2003
  3. miles.jg
    Replies:
    16
    Views:
    895
    Alf P. Steinbach
    Nov 14, 2007
  4. Brad Quinn

    controlling minOccurs and maxOccurs in wsdl

    Brad Quinn, Aug 1, 2003, in forum: ASP .Net Web Services
    Replies:
    1
    Views:
    572
    Brad Quinn
    Aug 1, 2003
  5. Patrick

    Relation between XmlNode and WSDL minoccurs or type

    Patrick, Oct 15, 2003, in forum: ASP .Net Web Services
    Replies:
    0
    Views:
    208
    Patrick
    Oct 15, 2003
Loading...

Share This Page