Skip to content

XML Escape

Make any text safe to place inside an XML element or attribute value.

Processed locally in your browser

Options
0 chars · 0 lines
The result will appear here.

What is XML Escape?

Five characters have special meaning in XML: the ampersand and the less-than sign always, the greater-than sign in some contexts, and the two quote characters inside attribute values. If they appear as data they must be written as the predefined entities &, <, >, " and '.

This tool applies exactly those replacements. You can disable quote escaping for element text, and optionally write every non-ASCII character as a numeric character reference such as é for pure-ASCII output. Characters that XML 1.0 forbids entirely (most control characters) cannot be represented even as references, so they are removed and reported.

How does it work?

  1. Paste the text you want to put in XML.
  2. Keep “Escape quotes” on for attribute values; turn it off for element text if you prefer.
  3. Optionally enable numeric references for non-ASCII characters.
  4. Copy the result, or Swap to verify it with the XML Unescape tool.

Common use cases

  • Putting user-supplied text safely into an XML template.
  • Escaping a code sample or formula (a < b && c > d) for an XML or SVG file.
  • Building attribute values that contain quotes.
  • Producing ASCII-only XML for legacy systems.

Examples

Try this input in the tool above:

Input
if (a < b && c > d) { print("Tom & Jerry's café"); }
Output
if (a &lt; b &amp;&amp; c &gt; d) { print(&quot;Tom &amp; Jerry&apos;s café&quot;); }

Privacy

XML Escape runs entirely in your browser. The text or files you provide are processed on your device and are not uploaded, logged or stored on our servers.

Limitations

Escaping makes text valid XML data; it is not a substitute for a proper XML builder when you generate large documents, and it does not sanitise markup.

Frequently asked questions

Do I always need to escape > ?

Only in the sequence ]]> inside text is it strictly required, but escaping every > is always valid and avoids surprises, so this tool does it.

What is the difference with the HTML entities encoder?

XML defines only five named entities. HTML has hundreds (&copy;, &nbsp;…), which an XML parser rejects unless declared. Use this tool for XML and the HTML tool for web pages.

Why were some characters removed?

XML 1.0 does not allow characters such as U+0000 to U+0008 even as numeric references. They are removed and counted in a warning.

More tools in JSON & Data →