In Xsd schema, is it possible to specify the child Xml elements in a complexType to appear in any order and maxOccurs > 1?

Answered In Xsd schema, is it possible to specify the child Xml elements in a complexType to appear in any order and maxOccurs > 1?

  • Friday, October 16, 2009 7:51 PM
     
     
    xs:sequence specifies that the child elements must appear in a sequence. Each child element can occur from 0 to any number of times.
    xs:all specifies that the child elements can appear in any order and that each child element can occur zero or one time.

    Is there a way to specify child elements can appear in any order and can occur from 0 to any number of times?

    Thanks.

All Replies

  • Saturday, October 17, 2009 10:31 AM
     
     Answered Has Code
    You can use a choice and then put maxOccurs="unbounded" on the choice e.g.

    <xs:element name="foo">
      <xsl:complexType>
        <xs:choice minOccurs="0" maxOccurs="unbounded">
          <xs:element name="child1" type="xs:int"/>
          <xs:element name="child2" type="xs:string"/>
        </xs:choice>
      </xs:complexType>
    </xs:element>
    that way the 'foo' element can have any number of 'child1' and 'child2' elements.
    MVP XML My blog