XML Schema allElement


XML Schema 参考手册Complete XML Schema Reference Manual

Definition and Usage

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

Element Information

  • Parent element: group, complexType, restriction (both simpleContent and complexContent), extension (both simpleContent and complexContent)

Syntax

<all
id=ID
maxOccurs=1
minOccurs=0|1
any attributes
>

(annotation?,element*)

</all>

(The ? sign declares that the element can appear zero or one time, while the * sign declares that the element can appear zero or more times among all elements.)

Attributes Description
id Optional. A unique identifier for the element.
maxOccurs Optional. The maximum number of times the element can appear. This value must be 1.
minOccurs Optional. The minimum number of times the element can appear. This value can be the 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 a 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 example above indicates that the "firstname" and "lastname" elements can appear in any order, and both elements must appear exactly 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!


XML Schema 参考手册Complete XML Schema Reference Manual Other extensions