apache/maven · error · XMLStreamException

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

Error message

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

What it means

checkUnknownAttribute(parser, attribute, tagName, strict) runs for each attribute the parser reports on an element. With strict=true, any attribute the model does not define for that element is rejected - the template comment notes strictXmlAttributes: in strict mode attributes are checked too, not only elements. The message names both the attribute and its tag.

Source

Thrown at src/mdo/reader-stax.vm:595

#end
        return tagName;
    }

    /**
     * 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 {
        // 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 {
        if (strict) {
            throw new XMLStreamException("Unrecognised tag: '" + parser.getName() + "'", parser.getLocation(), null);
        }

        for (int unrecognizedTagCount = 1; unrecognizedTagCount > 0;) {

View on GitHub (pinned to e4093d4e12)

Solutions

  1. Remove the offending attribute or fix its spelling - the message names the attribute and the tag.
  2. Check the model/XSD for the attributes allowed on that element and use only those.
  3. Move custom metadata into an element the model defines (e.g. a properties entry) instead of an attribute.
  4. Only if tolerating arbitrary attributes is acceptable, parse with strict=false.

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 model read
SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
Validator v = sf.newSchema(new StreamSource(xsdFile)).newValidator();
v.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")) {
        // attribute not in the model: fix the document or decide to read leniently
    }
    throw e;
}

Prevention

When it happens

Trigger: read(parser, true) on an element carrying an undeclared attribute: a typo'd attribute name, an attribute that belongs to a different schema version, or tooling-injected custom attributes the model never declared.

Common situations: Hand-edited XML with typos; documents written for a newer schema than the reader knows; tools adding proprietary metadata attributes; copy-paste from examples of a different format.

Related errors


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