Duplicate XML Attribute – Fix Repeated Attribute Names

Local only

An XML start tag cannot contain the same attribute name more than once, even when the duplicate values are identical.

34 chars · 1 line

Waiting for input

Loading XML parser…

XML attribute troubleshooting

How to fix a duplicate attribute in XML

The sample assigns port twice on the same service element. XML attributes on one element need unique names, so the parser rejects the start tag rather than choosing one value automatically. This tool is free to use. No account or payment is required.

Last updated

What you can do here

  • XML well-formedness validation
  • Broken XML example preloaded
  • Corrected XML comparison
  • .xml file import
  • Browser parser feedback
  • Browser-local processing

Steps

  1. Locate the start tag named in the parser error.
  2. Find any attribute name that appears more than once on that element.
  3. Keep the intended value or redesign the fields, remove the duplicate, and validate again.

XML parsers do not define a winner for duplicate attributes

Silently keeping the first or last value would make the document ambiguous. Well-formedness therefore requires attribute names to be unique within each start tag.

Repeated values may belong in child elements instead

If an element genuinely needs multiple values of the same kind, repeated child elements or another schema-defined collection often represent that data more clearly than duplicate attributes.

Repeated XML attribute example

Keep one authoritative port attribute on the service element.

Invalid XML

<service port="8080" port="9090"/>

Corrected XML

<service port="8080"/>

Common questions

Frequently asked questions

Can two XML attributes have the same name on one element?

No. Attribute names must be unique within a single element start tag.

Can different elements reuse the same attribute name?

Yes. The uniqueness rule applies within each individual element, not across the entire document.

Which duplicate XML attribute value does a parser keep?

A well-formed XML parser should reject the document instead of selecting one duplicate value.

Debugging a specific XML issue? Browse XML troubleshooting.