Default minOccurs and maxOccurs in XML Schema

This article explains the default values for the minOccurs and maxOccurs attributes in an XML Schema Definition (XSD). Understanding these defaults is essential for defining element cardinality correctly, avoiding schema validation errors, and designing predictable XML document structures.

In an XML Schema element declaration, the default value for both minOccurs and maxOccurs is 1.

Understanding the Defaults

Behavior When Omitted

If you declare an element in an XSD without explicitly specifying either attribute:

<xs:element name="username" type="xs:string"/>

The XML Schema processor automatically treats it as:

<xs:element name="username" type="xs:string" minOccurs="1" maxOccurs="1"/>

This means the element is strictly required and must appear exactly once within its parent container.

Common Modifications

To change this default behavior, you must explicitly set the attributes: