Paste text to make it safe inside an XML element or attribute, or paste escaped XML to turn the entities back into readable characters. Results update as you type and nothing leaves your browser.
Last updated:
0 characters
Advertisement
Advertisement
How to use the XML Escape / Unescape
Choose Escape, Unescape or Wrap in CDATA.
Paste your text into the left box (or click Sample).
Pick where the text will go: element text or an attribute, and how to handle non-ASCII characters.
Read the result on the right, with a count of every replacement.
Copy or download the output, or click Swap to reverse it.
XML special characters
Character
Entity
Numeric reference
Must be escaped
&
&
&
Always (text and attributes)
<
<
<
Always (text and attributes)
>
>
>
Only in "]]>" in text; escaping it everywhere is common and harmless
"
"
"
Inside attributes delimited by double quotes
'
'
'
Inside attributes delimited by single quotes
Escaping by context
Where the text goes
Input
Escaped
Element text
5 < 7 & "ok"
<n>5 < 7 & "ok"</n>
Double-quoted attribute
say "hi"
title="say "hi""
Single-quoted attribute
it's
title='it's'
CDATA section
a < b && c
<![CDATA[a < b && c]]>
Tips
Escape exactly once. Running escape twice turns & into &amp;, a common bug when text passes through two layers of code.
In code, prefer your XML library's serializer (for example DOM APIs, ElementTree or System.Xml) over hand-written string replacement: it escapes correctly for the context automatically.
The ampersand (&) and the less-than sign (<) must always be escaped in text and attribute values. The greater-than sign must be escaped when it appears in the sequence ]]> in text, and quotes must be escaped inside an attribute delimited by the same quote character. Escaping all five is always safe.
What are the five predefined XML entities?
& for &, < for <, > for >, " for " and ' for '. They are the only named entities XML defines without a DTD.
Both produce the same data. CDATA is convenient for large blocks with many < and & characters, such as code snippets. Escaping works everywhere, including attributes, where CDATA is not allowed.
Why are tabs and line breaks escaped in attributes?
XML parsers normalise attribute values, turning literal tabs and line breaks into spaces. Writing them as 	, and keeps them intact.
Which characters are not allowed in XML at all?
XML 1.0 forbids control characters U+0000 to U+001F except tab, line feed and carriage return, plus U+FFFE, U+FFFF and unpaired surrogates. They cannot appear even as numeric references, so this tool removes them by default.
Are all the tools on FreeToolCabin tested for quality and accuracy?
Yes! Every tool on our site undergoes automated Q/A testing in real browser environments to ensure high precision, correct output, and zero errors. If you happen to spot a bug or have a suggestion, please contact us at [email protected] and our team will review it right away.