XML

XML Escape and Unescape

Escapes text so it can be dropped into XML content or a quoted attribute, and decodes entity references back to plain text.

Loading the tool…

Processing happens locally in your browser. What you paste or load is processed by this page and is not uploaded to a server. Nothing is stored unless you use a control that says it stores something, and you can clear anything this site has kept from the privacy page.

How to use this tool

  1. Paste the text you want to put inside XML, or the escaped text you want back.
  2. Select Escape or Unescape.
  3. Copy the result into your element content or attribute value.

What xml escape and unescape does

Five characters cannot appear literally everywhere in XML: the ampersand, the two angle brackets, the double quote and the apostrophe. An unescaped ampersand in text is the single most common reason a generated XML file will not parse, and it usually arrives inside a URL that somebody concatenated into an element without thinking about it.

Escaping here covers element text and double-quoted attribute values, which is what almost everyone needs. Unescaping resolves named entities such as &, decimal references such as é and hex references such as é. Entities that a DTD defined are left as they are, because their definitions are not in front of us and inventing a value would be worse than leaving the text alone.

Frequently asked questions

The ampersand and the less-than sign must always be escaped in element text. The greater-than sign only strictly needs it after "]]", but escaping it always is simpler and harmless. Inside a double-quoted attribute value the double quote needs escaping too. This tool escapes all four.

Because it is safe as it stands in element text and inside a double-quoted attribute, which is what almost everybody uses. If you are writing attribute values in single quotes, escape it yourself as ' — the unescape direction here still decodes that entity.

You can, but the result will be a document turned into text rather than a working document — every tag becomes literal characters. That is what you want when embedding one XML document inside another as a value, and not what you want otherwise.