apache/maven · error · XMLStreamException

Unknown attribute '{}' for tag '{}'

Error message

Unknown attribute '{}' for tag '{}'

What it means

checkUnknownAttribute in the classic reader.vm template, twin of the stax template's method: for every attribute the parser reports on an element, strict mode throws if the model does not declare it (the strictXmlAttributes comment applies here too). The method also declares IOException, but the throw itself is an XMLStreamException naming the attribute and tag.

Source

Thrown at src/mdo/reader.vm:702

        return true;
    } //-- boolean checkFieldWithDuplicate(XMLStreamReader, String, String, Set<String>)

    /**
     * Method checkUnknownAttribute.
     *
     * @param parser a parser object.
     * @param strict a strict object.
     * @param tagName a tagName object.
     * @param attribute a attribute object.
     * @throws XMLStreamException XMLStreamException if
     * any.
     * @throws IOException IOException if any.
     */
    private void checkUnknownAttribute(XMLStreamReader parser, String attribute, String tagName, boolean strict)
        throws XMLStreamException, IOException {
        // strictXmlAttributes = true for model: if strict == true, not only elements are checked but attributes too
        if (strict) {
            throw new XMLStreamException("Unknown attribute '" + attribute + "' for tag '" + tagName + "'", parser.getLocation(), null);
        }
    } //-- void checkUnknownAttribute(XMLStreamReader, String, String, boolean)

    /**
     * Method checkUnknownElement.
     *
     * @param parser a parser object.
     * @param strict a strict object.
     * @throws XMLStreamException XMLStreamException if
     * any.
     * @throws IOException IOException if any.
     */
    private void checkUnknownElement(XMLStreamReader parser, boolean strict)
        throws XMLStreamException, IOException {
        if (strict) {
            throw new XMLStreamException("Unrecognised tag: '" + parser.getLocalName() + "'", parser.getLocation(), null);
        }

View on GitHub (pinned to e4093d4e12)

Solutions

  1. Remove the attribute or correct its name - the message identifies both attribute and tag.
  2. Check the model/XSD for allowed attributes on that element.
  3. Encode custom metadata in a model-defined element instead.
  4. Parse with strict=false only if arbitrary attributes are acceptable.

Example fix

<!-- before -->
<dependency version="1.0">
  <groupId>com.example</groupId>
  <artifactId>app</artifactId>
</dependency>

<!-- after -->
<dependency>
  <groupId>com.example</groupId>
  <artifactId>app</artifactId>
  <version>1.0</version>
</dependency>
Defensive patterns

Strategy: try-catch

Validate before calling

// XSD validation flags undeclared attributes before the read
SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
sf.newSchema(new StreamSource(xsdFile)).newValidator().validate(new StreamSource(xmlFile));

Try / catch

try {
    Model model = reader.read(parser, true);
} catch (XMLStreamException e) {
    if (e.getMessage() != null && e.getMessage().startsWith("Unknown attribute")) {
        // fix the document, or decide on a lenient read
    }
    throw e;
}

Prevention

When it happens

Trigger: read(parser, true) over an element carrying an undeclared attribute: typo'd names, attributes from another schema version, or tool-injected custom attributes.

Common situations: Hand-edited XML with attribute typos; documents written for newer schemas read by older readers; tools adding metadata attributes the model never declared.

Related errors


AI-assisted analysis of apache/maven@e4093d4e12 (2026-08-21). Data as JSON: /api/errors/96524d01f39afd0f. Report an issue: GitHub.