XML Schema sequence element

Definition and usage

The sequence element requires the elements within the group to appear in the specified order within the containing element. Each child element can occur 0 times to any number of times.

Element information

Occurrence Once within the group; otherwise unrestricted.
Parent element group, choice, sequence, complexType, restriction (simpleContent), extension (simpleContent), restriction (complexContent), extension (complexContent)
Content annotation, any, choice, element, group, sequence

Syntax

<sequence
id=ID
maxOccurs=nonNegativeInteger|unbounded
minOccurs=nonNegativeInteger
any attributes
>
(annotation?,(element|group|choice|sequence|any)*)
</sequence>

(Declaration in the sequence element that this element can appear zero or one time.)

Attribute Description
id Optional. Specifies the unique ID of the element.
maxOccurs Optional. Specifies the maximum number of occurrences that the any element can appear in the parent element. This value can be an integer greater than or equal to zero. To specify no limit on the maximum number of occurrences, use the string "unbounded". The default value is 1.
minOccurs Optional. Specifies the minimum number of occurrences that the any element can appear in the parent element. This value can be an integer greater than or equal to zero. To specify that this any group is optional, set this attribute to zero. The default value is 1.
any attributes Optional. Specifies any other attributes with a non-schema namespace.

Instance

Example 1

This example is a declaration for the "personinfo" element, which must sequentially contain the following 5 elements: "firstname", "lastname", "address", "city", and "country".

<xs:element name="personinfo">
  <xs:complexType>
    <xs:sequence>
      <xs:element name="firstname" type="xs:string"/>
      <xs:element name="lastname" type="xs:string"/>
      <xs:element name="address" type="xs:string"/>
      <xs:element name="city" type="xs:string"/>
      <xs:element name="country" type="xs:string"/>
    </xs:sequence>
  </xs:complexType>
</xs:element>

Example 2

This example is a declaration for the "pets" element, which can contain zero or more dog and cat elements:

<xs:element name="pets">
  <xs:complexType>
    <xs:sequence minOccurs="0" maxOccurs="unbounded">
      <xs:element name="dog" type="xs:string"/>
      <xs:element name="cat" type="xs:string"/>
    </xs:sequence>
  </xs:complexType>
</xs:element>