# Attribute was already specified for element

Source: https://xmlvalid.com/errors/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

libxml2, which xmlvalid validates with, reports it as [Attribute redefined](https://xmlvalid.com/errors/attribute-redefined): `Attribute id redefined`

## Example that fails

```xml
<item id="1" id="2"/>
```

## Fixed

```xml
<item id="1"/>
```
