XML Schema sequence element

Definition and usage

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

Element information

Occurrence count 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, this element can occur zero or one time.)

Attribute Description
id Optional. Specifies a unique ID for the element.
maxOccurs Optional. Specifies the maximum number of occurrences that the any element can appear in the parent element. This value can be any non-negative integer. To place no limit on the maximum count, 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 any non-negative integer. 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 include 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 include 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>