XML error reference · XV009

Duplicate attribute

The same attribute name appears twice on one element.

What your parser calls it

The same problem, reported differently by each parser. If you arrived here from one of these strings, you are in the right place.

ParserMessage
libxml2 / xmllintAttribute role redefined
Firefox DOMParserXML Parsing Error: duplicate attribute
.NET XmlException'role' is a duplicate attribute name.

What causes it

An element may not carry the same attribute twice. That is the specification's Unique Att Spec constraint. Because the check is on the expanded name, two different prefixes bound to the same namespace URI also collide even though the text differs. Merging attribute maps in code, or templating that emits a default and then an override, are the usual causes.

See it happen

Triggers the error
<user id="1" role="admin" role="editor"/>
Corrected
<user id="1" role="editor"/>

How to fix it

Remove the duplicate and keep the value you actually want. When attributes are built programmatically, use a map keyed by expanded name so a later write replaces the earlier one instead of appending a second attribute.

Fix your own document

Paste your own document below. Press Sample if you want the broken example above loaded instead. Nothing you paste leaves this tab.

XML Validator

Well-formedness and schema validation. Nothing is uploaded.

Input
WaitingPaste a document to check it. Validation runs as you type.

Everything runs in this tab. Nothing you paste is uploaded, logged or sent anywhere. Open your network panel and check.

Tools that catch this

Background reading

Errors this fixes

Every XML error, explained