Skip to main content

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

XSD validation error

The attribute is required but missing

The schema marks an attribute use="required" and the document does not carry it. Well-formed, and rejected by the first consumer that validates.

Element 'order': The attribute 'id' is required but missing. (line 2)

What it means

An attribute declared with use="required" is part of the contract, not a suggestion. XML itself has no opinion about which attributes an element carries, so nothing catches this until a schema is applied — which is usually at the receiving end, after the document has already been sent.

Required attributes are where identifiers live: order ids, currency codes, schema versions. Their absence is rarely cosmetic, so this error normally means a field was dropped upstream rather than mistyped.

What usually causes it

  • A generator that emits the attribute only when its value is non-empty, so an empty value becomes a missing attribute.
  • A field renamed on one side of an integration and not the other.
  • Mapping code that writes the value as a child element when the schema wants an attribute.
  • A partial object serialized before it was fully populated.

How to fix it

  • Add the attribute. If the value is genuinely unknown, the schema is telling you the document is not ready to send.
  • Emit required attributes unconditionally — an empty string is a value; a missing attribute is a contract breach.
  • If the field really is optional in your domain, change the schema to use="optional" rather than shipping documents that fail it.

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-complex-type.4: Attribute 'id' must appear on element 'order'.
  • .NET System.Xml

    The required attribute 'id' is missing.

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>
  <customer>Ada</customer>
  <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>

The terms behind it

Each of these is defined in one sentence and then demonstrated against the parser.

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.