Skip to main content

XSD validation error

The attribute is not allowed

The document carries an attribute the schema never declared. XSD is closed by default: anything not named is forbidden rather than ignored.

Element 'order', attribute 'ref': The attribute 'ref' is not allowed. (line 2)

What it means

A complex type permits exactly the attributes it declares. Unlike a permissive JSON consumer, a schema validator does not skip what it does not recognise — an undeclared attribute is an error, even one that is obviously harmless.

This is the failure that appears when a sender adds a field. Their document is richer, yours is a validator, and the contract said no.

What usually causes it

  • A partner adding a field without a schema revision agreed on both sides.
  • Debug or trace attributes left on a document by a middleware layer.
  • A typo in an attribute name — the correct one goes missing and the misspelling is rejected as unknown.
  • A namespace-qualified attribute from an extension the schema does not import.

How to fix it

  • Remove the attribute, or declare it in the schema — those are the only two honest options.
  • For genuinely extensible documents, declare <xs:anyAttribute namespace="##other"/> so extensions are allowed by design.
  • Check the spelling first: an unexpected attribute and a missing required one usually arrive together, and are the same typo.

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.3.2.2: Attribute 'ref' is not allowed to appear in element 'order'.
  • .NET System.Xml

    The 'ref' attribute is not declared.

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" ref="X">
  <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:element name="order">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="customer" type="xs:string"/>
        <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.