Unescaped Ampersand in XML – Fix & Entity Errors

Local only

A bare ampersand starts XML entity-reference syntax, so ordinary text containing & must escape it as & unless a valid entity follows.

41 chars · 1 line

Waiting for input

Loading XML parser…

XML entity troubleshooting

How to fix an unescaped ampersand in XML

The sample places a literal & between words. XML interprets ampersand as the start of an entity or character reference, so ordinary text must encode the character as & before the document can parse. 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 ampersand nearest the parser error.
  2. Determine whether it starts an intended entity reference or is literal text.
  3. Replace a literal ampersand with & and validate the complete document again.

Ampersand is XML markup syntax

XML reserves & for entity references. Text such as A & B is not valid character data until the ampersand is escaped. The parser cannot safely guess whether the following characters were meant to form an entity name.

Avoid double-escaping existing entities

If the source already contains &, changing it to & changes the data. Fix only bare ampersands that represent the literal character.

Literal ampersand in XML text

Encode the data character with the predefined & entity.

Invalid XML

<company>Research & Development</company>

Corrected XML

<company>Research &amp; Development</company>

Common questions

Frequently asked questions

How do I write an ampersand in XML text?

Use &amp; when the data should contain a literal ampersand character.

Do ampersands in XML attribute values also need escaping?

Yes. A literal ampersand in an attribute value must also be represented with valid entity syntax.

Should I replace every & with &amp;?

No. Existing valid entity or character references already use ampersand syntax and should not be double-escaped.

Debugging a specific XML issue? Browse XML troubleshooting.