XML Schema all element

Definition and usage

The all element specifies that child elements can appear in any order, and each child element can appear zero or once.

Element information

Appearance times One
Parent element group, restriction (simpleContent), extension (simpleContent), restriction (complexContent), extension (complexContent), complexType
Content annotation, element

Syntax

<all
id=ID
maxOccurs=1
minOccurs=0|1
any attributes
>
(annotation?,element*)
</all>

(The ? symbol indicates that the element can appear zero or once, while the * symbol indicates that the element can appear zero or multiple times in all elements.)

Attribute Description
id Optional. The unique identifier of the element.
maxOccurs Optional. The maximum number of times an element can appear. This value must be 1.
minOccurs Optional. The minimum number of times an element can appear. This value can be an integer 0 or 1. To specify that the element is optional, set this attribute to 0. The default value is 1.
any attributes Optional. Specifies any other attributes with non-schema namespace.

Example 1

<xs:element name="person">
  <xs:complexType>
    <xs:all>
      <xs:element name="firstname" type="xs:string"/>
      <xs:element name="lastname" type="xs:string"/>
    </xs:all>
  </xs:complexType>
</xs:element>

The above example indicates that the "firstname" and "lastname" elements can appear in any order, and both elements must and can only appear once!

Example 2

<xs:element name="person">
  <xs:complexType>
    <xs:all minOccurs="0">
      <xs:element name="firstname" type="xs:string"/>
      <xs:element name="lastname" type="xs:string"/>
    </xs:all>
  </xs:complexType>
</xs:element>

The example above indicates that the "firstname" and "lastname" elements can appear in any order, and each element can appear zero or one time!