XML escape and unescape — the five predefined entities

Paste text to make it safe inside an XML element or attribute, or paste escaped XML to read it. Only the five entities XML defines are used, so the output works in any XML parser.

Live demo · real result from this tool
Direction

Encoded

<note lang="en">Fish & Chips 'tonight'</note>

Processed on your device — nothing is uploaded.

How to use the XML encoder and decoder

  1. Set Direction to Encode to escape text, or Decode to unescape it.
  2. Paste your text into Input.
  3. When encoding, keep Escape quotes (needed in attribute values) ticked unless the text only goes between tags.
  4. Tick Write non-ASCII as numeric references if the target cannot store UTF-8.
  5. Copy the Encoded or Decoded result.

What it does and when to use it

An XML parser stops with an error at a bare & or < in text, because those characters start entities and tags. Escaping is needed whenever you place user text, product names, URLs with query strings or code snippets into an XML file by hand: RSS and Atom feeds, sitemaps, SVG, Android string resources, Maven or .NET config files, SOAP messages.

Decoding helps when you need the original text back from a feed or a config value, for example a URL in a sitemap written as ?a=1&amp;b=2.

If you are working with HTML instead, the HTML encoder and HTML decoder know the full list of HTML named entities. For numeric references only, use the numeric HTML entities tool. If the value is going into a URL rather than XML, use the URL encoder.

How it works

The XML 1.0 specification predefines exactly five entities. Encoding replaces each character in one pass:

Character Escaped as
& &amp;
< &lt;
> &gt;
" &quot; (with Escape quotes on)
' &apos; (with Escape quotes on)

With the non-ASCII option on, every character above code 127 becomes a decimal reference such as &#233;. Decoding turns the five entities and any decimal or hex numeric reference back into characters; anything else stays as written. Everything runs in your browser.

Worked examples

<a>Fish & Chips</a>                          →  &lt;a&gt;Fish &amp; Chips&lt;/a&gt;
<note lang="en">Fish & Chips 'tonight'</note> (quotes off)
                                             →  &lt;note lang="en"&gt;Fish &amp; Chips 'tonight'&lt;/note&gt;
Café ✓  (non-ASCII as references)            →  Caf&#233; &#10003;
&lt;b&gt; &apos;x&apos; &#233; &nbsp;  (Decode) →  <b> 'x' é &nbsp;

Limits and tips

  • Escaping is not validation. The tool does not check that your XML is well formed.
  • Control characters that XML 1.0 forbids, such as most bytes below 32, are not removed. Strip them before escaping if your data may contain them.
  • For large blocks of code inside XML, a CDATA section can be easier to read than escaping every character.

Frequently asked questions

Which characters must be escaped in XML?
Ampersand and less-than must always be escaped in text, as &amp; and &lt;. Greater-than is escaped too, to be safe. Inside attribute values, the quote character that surrounds the value must be escaped as &quot; or &apos;.
Why does &nbsp; stay as it is when I decode?
XML has only five built-in entities, amp, lt, gt, quot and apos. &nbsp; is an HTML entity, so an XML parser would reject it unless a DTD defines it. This tool decodes the five and numeric references, and leaves everything else untouched so you can see it.
When should I untick "Escape quotes"?
When the text goes between tags rather than into an attribute. Quotes are legal in element text, and leaving them readable keeps the XML easier to scan. Keep the option on if you are not sure.
Do I need to escape accented letters or emoji?
Not if the file is saved as UTF-8, which is the XML default. Tick "Write non-ASCII as numeric references" only when the XML will be stored or sent in an encoding that cannot hold those characters.
Can I use this for HTML?
For the markup characters, yes; the results are valid in HTML too. But HTML has hundreds of named entities, so for decoding HTML use an HTML decoder instead.

Sources

  1. Extensible Markup Language (XML) 1.0 (Fifth Edition) — W3C, accessed 2026-10-08

Written by the ToolsRift team · Last updated

Pages are drafted with AI assistance and checked by automated tests. How we write and check pages.

Was this tool useful?

Report a problem

Start typing to search every tool.

↑ ↓ to moveEnter to openEsc to close