XML Escape / Unescape

Escape text for XML elements and attributes, decode XML entities, or wrap text safely in CDATA.

Runs in your browser. Nothing is uploaded.

How to use the XML Escape / Unescape

  1. Type or paste text, or open a file.
  2. Choose Escape for XML to make text safe inside an element or attribute, Unescape to turn references back into characters, or Wrap in CDATA.
  3. For attribute values, keep Escape quotes ticked. Tick Non-ASCII if the receiving system can't handle UTF-8.
  4. Copy or download the result.

Put any text safely inside XML

XML gives a few characters a special meaning: < starts a tag and & starts a reference. If text containing them is inserted into XML as it is, the document breaks, or worse, the text is read as markup. Escaping replaces those characters with references that parsers turn back into the original text. It is the XML equivalent of quoting a string in code.

Three ways to encode

  • Escape for XML replaces &, < and > with &amp;, &lt; and &gt;. With Escape quotes, " and ' become &quot; and &apos;, which you need inside attribute values. This is the safe default for any value you insert into a document.
  • Non-ASCII as numeric references writes characters such as é or € as &#233; and &#8364;, for older systems that mangle UTF-8.
  • Wrap in CDATA keeps text readable by marking a whole block as character data. Any ]]> inside is split across two sections so it can’t end the block early.

Decode it again

Unescape reverses the process: references become characters and CDATA wrappers are removed, leaving plain text. It is useful for reading values copied out of XML files or logs, where escaped HTML is common.

Clean out invalid characters

Text copied from documents, terminals or binary data can contain control characters that XML 1.0 forbids completely. A single one makes the whole file unreadable for strict parsers. When escaping, the tool removes them and tells you how many it found.

A better long-term fix

If you build XML in code, use an XML library or your language’s escaping function instead of joining strings, so escaping can’t be forgotten. This tool is ideal for one-off values, test data and checking what a library should produce.

Private

Nothing is uploaded. To check a whole document, use the XML Viewer, Formatter & Validator.

Frequently asked questions

Which characters must be escaped in XML?

In text, & must become &amp; and < must become &lt;. > is escaped too, because ]]> isn’t allowed in text. Inside attribute values, the quote character used around the value must also be escaped, as &quot; or &apos;.

When should I use CDATA instead?

CDATA is handy for longer blocks with many special characters, such as HTML snippets or code samples, because the content stays readable. It can’t contain the sequence ]]>, so the tool splits it automatically when it appears.

Why were some characters removed?

XML 1.0 doesn’t allow most control characters (codes 0–31 except tab, line feed and carriage return), even as references. They often sneak in from copied text or binary data. The tool removes them and tells you how many.

Does unescape understand &nbsp; and other HTML entities?

It decodes the five XML entities and all numeric references like &#233; and &#x1F600;. HTML-only names such as &nbsp; are left as they are, because they aren’t defined in XML.

Is my text uploaded?

No. Everything happens in your browser.

Tutorials

Tutorial · 3 min · beginner

How to decode escaped text from XML

Turn &lt;, &amp; and numeric references back into readable characters, for example to read HTML stored inside an XML element.