XML Escape
Make any text safe to place inside an XML element or attribute value.
Processed locally in your browser/ Your data stays in your browser.
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?
- Paste the text you want to put in XML.
- Keep “Escape quotes” on for attribute values; turn it off for element text if you prefer.
- Optionally enable numeric references for non-ASCII characters.
- 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:
if (a < b && c > d) { print("Tom & Jerry's café"); }if (a < b && c > d) { print("Tom & Jerry's café"); }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 (©, …), 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.
Related tools
XML Unescape
Convert XML entities and numeric character references back into the characters they stand for.
JSON & Data
XML Formatter & Beautifier
Turn compressed or messy XML into a cleanly indented document that is easy to read and review.
JSON & Data
HTML Entities Encoder
Escape markup characters, or turn every non-ASCII character into an entity such as é or é.
Encoding & Decoding
JSON Escape
Turn any text, even a whole JSON document, into a safe string you can embed inside another JSON value.
JSON & Data
Unicode Escape Converter
Turn é, ☕ and 😀 into \u00E9, \u2615 and \uD83D\uDE00 (or another escape style) for source code, JSON or CSS.
Encoding & Decoding
XML to JSON Converter
Turn an XML document into JSON, keeping attributes, repeated elements and text content in a predictable structure.
JSON & Data