Skip to main content

Search 400 pages — tools, formats, elements, namespaces, directory, comparisons, XPath, datatypes, glossary, parse errors, schema errors, use cases, guides, blog and product.

XSD validation error

The element is not nillable

The instance marks an element xsi:nil="true", but its XSD declaration does not permit an explicit nil value in that position.

Element 'middleName': The element is not 'nillable'. (line 4)

What it means

xsi:nil is not a universal XML spelling for null. It has schema-defined meaning only when the matching xs:element declaration carries nillable="true".

Optionality and nillability are independent: minOccurs="0" permits the element to be absent, while nillable permits a present element to say it has no value.

What usually causes it

  • A serializer maps every application null to xsi:nil without reading the schema.
  • The producer sends an explicit nil where the contract expects the element to be omitted.
  • A schema revision removed nillable="true" but older producers still emit xsi:nil.
  • The document is being validated against a stricter schema version than the producer used.

How to fix it

  • Omit the element when its declaration has minOccurs="0" and absence carries the intended meaning.
  • Declare the element nillable="true" when an explicit null is genuinely part of the contract.
  • Do not replace nil with an empty element automatically: an empty string is a value for xs:string and fails many other datatypes.

The same error elsewhere

libxml2 words these plainly. Xerces numbers them, and those cvc- codes are what most people end up searching for.

  • Xerces (Java)

    cvc-elt.3.1: Attribute 'xsi:nil' must not appear on the element 'middleName', because the {nillable} property is false.
  • .NET System.Xml

    The element is not nillable, so the attribute 'xsi:nil' cannot be used.

Before and after

Both documents below are well-formed XML — that is the point. The test suite re-checks them against the real validator on every build: the first is confirmed to produce the exact message above, the second to validate cleanly.

Fails validation
<?xml version="1.0" encoding="UTF-8"?>
<order id="A-1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <customer>Ada</customer>
  <middleName xsi:nil="true"/>
  <issued>2026-01-31</issued>
  <state>open</state>
  <line>
    <code>AB-1234</code>
    <qty>2</qty>
  </line>
</order>
Validates
<?xml version="1.0" encoding="UTF-8"?>
<order id="A-1">
  <customer>Ada</customer>
  <issued>2026-01-31</issued>
  <state>open</state>
  <line>
    <code>AB-1234</code>
    <qty>2</qty>
  </line>
</order>

The schema both are checked against

order.xsd
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:simpleType name="status">
    <xs:restriction base="xs:string">
      <xs:enumeration value="open"/>
      <xs:enumeration value="closed"/>
    </xs:restriction>
  </xs:simpleType>
  <xs:simpleType name="sku">
    <xs:restriction base="xs:string">
      <xs:pattern value="[A-Z]{2}-\d{4}"/>
    </xs:restriction>
  </xs:simpleType>
  <xs:simpleType name="shortLabel">
    <xs:restriction base="xs:string">
      <xs:minLength value="3"/>
    </xs:restriction>
  </xs:simpleType>
  <xs:element name="order">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="customer" type="xs:string"/>
        <xs:element name="middleName" type="xs:string" minOccurs="0"/>
        <xs:element name="nickname" type="shortLabel" minOccurs="0"/>
        <xs:element name="issued" type="xs:date"/>
        <xs:element name="state" type="status"/>
        <xs:element name="line" minOccurs="1" maxOccurs="2">
          <xs:complexType>
            <xs:sequence>
              <xs:element name="code" type="sku"/>
              <xs:element name="qty" type="xs:positiveInteger"/>
            </xs:sequence>
          </xs:complexType>
        </xs:element>
      </xs:sequence>
      <xs:attribute name="id" type="xs:string" use="required"/>
    </xs:complexType>
  </xs:element>
</xs:schema>

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.