Format Code Now
/
Encode & decodeXML Escape / Unescape Next: XML URL Encoding ›

XML Escape / Unescape

ED-65

Escape the five special XML characters, turn entities back into text, or wrap text in a CDATA section so nothing needs escaping.

Runs in your browser. Nothing is uploaded.

Text or escaped XML text

Result

How to use it

  1. Paste the text, or the escaped XML text, into the input box.
  2. Leave Escape quotes on for attribute values, or turn it off for element text.
  3. Click Escape, Unescape or Wrap in CDATA.
  4. Copy the result or download it as a .txt file.

Escape and unescape

Escape replaces & with &amp;, < with &lt;, > with &gt;, " with &quot; and ' with &apos;. In element text only & and < are required, so you can turn the quote option off. Unescape reads those five entities and numeric references such as &#65;, and stops on anything else, such as &nbsp;, which XML does not define, or on a bare & that does not start an entity.

Wrap in CDATA

A CDATA section holds text where &, < and > are literal. The tool wraps your text in the section markers. Because ]]> would end the section early, any ]]> in the text is split across two sections, which parsers read back as the original text. CDATA is valid only as element content, so do not use it for attribute values.

Invalid characters

XML 1.0 forbids most control characters, unpaired surrogates and U+FFFE and U+FFFF, even in CDATA, and an escape cannot make them legal. The tool reports the first one with its position, or removes them if you choose that. It does not parse or validate a whole XML document.

Error messages and what to do

MessageWhat it meansFix
is not allowed in XML 1.0The text contains a character XML 1.0 does not permit, such as a control character.Remove it, or choose Remove them.
Unknown XML entityUnescape found an entity XML does not define, such as &nbsp;.Use &#160; or decode it with the HTML entities tool.
A bare & atAn & does not begin an entity.Write it as &amp;.

Questions people ask

How do I escape special characters in XML?

Paste the text and click Escape. The characters & < > " and ' are replaced with &amp; &lt; &gt; &quot; and &apos;. Use it for attribute values and element text before putting them in an XML file.

When should I use CDATA instead of escaping?

When a block holds a lot of markup-like text, such as code or HTML, and you want it readable in the file. CDATA keeps the text literal. For short values and attributes, escaping is simpler and works everywhere.

How do I include ]]> inside CDATA?

You cannot write it directly because it ends the section. The standard approach is to split it, ending one section after ]] and starting a new one with >. The Wrap in CDATA button does this for you.

Why does XML reject &nbsp;?

XML defines only five named entities: amp, lt, gt, quot and apos. Names like nbsp come from HTML and need a DTD in XML. Use the numeric form &#160; instead.

Do I have to escape quotes in element text?

No. In element text only & and < must be escaped. Quotes matter only inside attribute values, where the quote character that wraps the value must be escaped. Turn off the quote option for element text.

How do I unescape XML entities?

Paste the escaped text and click Unescape. The five XML entities and numeric references like &#65; and &#x41; become characters. Anything else is reported, so you know what was not valid XML.

About this tool

Escape replaces & < > " and ' with &amp; &lt; &gt; &quot; and &apos;; turn off the quote option for element text, where quotes need no escaping. Unescape accepts only those five entities and numeric references, and stops on anything else, such as &nbsp;, or on a bare &. Wrap in CDATA puts the text inside a CDATA section, where nothing needs escaping, and splits any ]]> in it across two sections because that sequence would end the section early. CDATA works only as element content, not in attribute values. XML 1.0 forbids most control characters even inside CDATA, so those are reported with their position or removed. The tool does not parse or validate a whole XML document.

Format Code Now: free, no ads, no accounts. Your input stays in your browser.