Attribute was already specified for element

The same attribute appears twice on one element.

The message, as Java reports it
Attribute "id" was already specified for element "item".

Why it happens

  • XML built by string concatenation that adds an attribute again.
  • A template that sets a default and then the real value.

How to fix it

Keep one occurrence. An attribute name may appear only once per element.

Java's schema validation (javax.xml.validation.Validator, and JAXB or Spring on top of it) throws at the first error unless you set an ErrorHandler whose error() records the SAXParseException and carries on; each one has getLineNumber() and getColumnNumber(). A well-formedness error ends parsing whatever the handler does.

The same problem in xmlvalid

xmlvalid validates with libxml2, which reports it as Attribute redefined. It checks the whole document in your browser and lists every schema error with its line and column, not only the first.

Attribute id redefined

Example

Reports the error
<item id="1" id="2"/>
Fixed
<item id="1"/>