Re: Either-Or elements

This is true. Force of habit I guess, a lot of schemas I've worked on mix all the constructs for various reasons. For example, I'll often see element nodes as sisters of the choice nodes, and doing this is often accomplished in a sequence...

-BKN

  ----- Original Message ----- 
  From: Pete Hendry 
  To: Bryce K. Nielsen 
  Cc: xmlschema-dev@w3.org 
  Sent: Monday, March 21, 2005 10:39 PM
  Subject: Re: Either-Or elements


  What does the sequence add?


  <xsd:complexType name="somethingType">
    <xsd:choice minOccurs="1" maxOccurs="1">
      <xsd:element name="foo"/>
      <xsd:element name="bar"/>
    </xsd:choice>
  </xsd:complexType>

  or more simply 


  <xsd:complexType name="somethingType">
    <xsd:choice>
      <xsd:element name="foo"/>
      <xsd:element name="bar"/>
    </xsd:choice>
  </xsd:complexType>

  Pete

  Bryce K. Nielsen wrote: 
    You'll want to use the xsd:choice node. i.e.:

    <xsd:complexType name="somethingType">
      <xsd:sequence minOccurs="1" maxOccurs="1">
        <xsd:choice>
          <xsd:element name="foo"/>
          <xsd:element name="bar"/>
        </xsd:choice>
      </xsd:sequence>
    </xsd:complexType>

    By nesting the xsd:choice within a xsd:sequence node allows you to force how many times this "choice" is allowed. From your sample schema, it seemed like you only wanted it to occur once, thus the min/max in the sequence...

    HTH,

    Bryce K. Nielsen
    SysOnyx, Inc. (www.sysonyx.com)
    Makers of xmlDraft, the Smart XSD Editor
    http://www.sysonyx.com/products/xmldraft


      ----- Original Message ----- 
      From: RPearse@360commerce.com 
      To: xmlschema-dev@w3.org 
      Sent: Monday, March 21, 2005 12:02 PM
      Subject: Either-Or elements



      Using a DTD, I can specify that the something element can only have foo or bar, but not both with this: <!ELEMENT something ((foo|bar)*)> 

      In an XSD, I would have this: 

      <?xml version="1.0"?> 

      <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"> 

      <xsd:element name="something" type="somethingType" /> 

      <xsd:complexType name="somethingType"> 
              <xsd:sequence> 
                      <xsd:element name="foo" minOccurs="1" maxOccurs="1" /> 
                      <xsd:element name="bar" minOccurs="1" maxOccurs="1" /> 
              </xsd:sequence> 
      </xsd:complexType> 

      How would I specify that the user has to have the foo or bar element, but not both? Currently, this XSD seems to require that you have exactly one foo and one bar in your instance document. 

      Thanks, 

      Robert 

Received on Tuesday, 22 March 2005 05:53:45 UTC