XSD guide
XSD minOccurs vs nillable
The difference between an absent element and a present element with xsi:nil, with schemas and instance documents for each case.
8 min read · Updated 2026-08-21
The short answer
minOccurs controls whether the element may be absent. nillable controls whether a present element may carry xsi:nil="true". They solve different problems: use minOccurs="0" for optional presence, nillable="true" for an explicit null, or both when both states are meaningful.Model three different states
XML can distinguish absence, an empty value, and an explicit nil. A schema should permit only the states the receiving system can interpret consistently.
- Absent: there is no element node.
- Empty: <middleName/> is present with an empty string value.
- Nil: <middleName xsi:nil="true"/> is present and explicitly has no value.
Make absence optional with minOccurs
The default minOccurs is 1. Set it to 0 when omitting the element is valid. This says nothing about xsi:nil on an element that is present.
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="person">
<xs:complexType>
<xs:sequence>
<xs:element name="middleName" type="xs:string" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema><person/>Make explicit null valid with nillable
A nilled element must be present, declare the xsi namespace, and carry no element or character content. Attributes may still be present if its type permits them.
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="person">
<xs:complexType>
<xs:sequence>
<xs:element name="middleName" type="xs:string" minOccurs="0" nillable="true"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema><person xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<middleName xsi:nil="true"/>
</person>Get started
Bring order to the XML your team can't afford to ignore.
Create a free account and get a private workspace to search, validate, diff, and monitor your XML feeds, sitemaps, schemas, and vendor integrations.