XML Escape and Unescape
ED-09Paste text to replace the five XML special characters with entities, or paste escaped text to get the original back. Characters that XML 1.0 forbids are reported with their position.
Runs in your browser. Nothing is uploaded.
Text or escaped XML text
Result
How to use it
- Paste your text into the input box.
- Choose Escape or Unescape.
- Untick the quotes box if the text is element content, where quotes do not need escaping.
- If the tool reports an invalid character, fix it in the source, or choose Remove them.
- Copy the result.
The five XML entities
XML predefines five entities: & for the ampersand, < and > for the angle brackets, " for the double quote and ' for the apostrophe. In element content only the ampersand and the opening angle bracket must be escaped. In attribute values the quote that surrounds the value must be escaped as well. Escaping all five is always correct, so that is the default. The closing angle bracket is escaped too, which also avoids an accidental ]]> sequence.
Characters XML cannot hold
XML 1.0 allows tab, line feed, carriage return and characters from U+0020 up, except surrogates, U+FFFE and U+FFFF. Other control characters, such as U+0008 or U+000C, are not allowed even as a numeric reference like . The tool reports the first one with its line and column and the count of the rest. You can remove them instead, but that changes your data, so it is an option you choose rather than the default.
What Unescape does not do
Unescape accepts only the five XML entities and numeric references, and stops on anything else, such as or a lone ampersand, with the position. It does not parse a whole XML document, resolve custom entities defined in a DTD, or interpret CDATA sections. To check that a whole document is well formed, use the XML Formatter on this site.
Error messages and what to do
| Message | What it means | Fix |
|---|---|---|
U+0008 at line 1, column 2 is not allowed in XML 1.0. XML 1.0 forbids most control characters (everything below U+0020 except tab, line feed and carriage return), unpaired surrogates, U+FFFE and U+FFFF. Remove it, or choose "Remove them". | The text holds a character that XML 1.0 does not allow, even when escaped. | Delete it in the source, or set the invalid characters option to Remove them. |
Unknown XML entity at line 1, column 1. XML defines only & < > " and '. Use the HTML entity tool for names such as . | Unescape found an entity name that XML does not predefine. | Use the HTML entities tool for HTML names, or replace the name with a numeric reference. |
A bare & at line 1, column 5 is not valid XML. It must start an entity such as & or &. | An ampersand is not followed by a complete entity ending in a semicolon. | Write it as & or complete the entity. |
Questions people ask
How do I escape special characters in XML?
Paste the text and press Escape. The ampersand, angle brackets, double quote and apostrophe become &, <, >, " and '. Paste the result into your element or attribute.
Which characters must be escaped in XML?
In element content, the ampersand and the less-than sign. In an attribute value, also the quote character that delimits it. Escaping the greater-than sign is optional, except in the sequence ]]>, where it must be escaped.
Why does XML reject my control characters?
XML 1.0 does not allow most characters below U+0020, such as backspace or form feed, in any form, including as . The tool lists the first offender and its position so that you can find and remove it in the source data.
Is valid in XML?
No. It is an HTML entity, and XML defines only five names. In XML, write the character itself or a numeric reference,  , unless a DTD defines . Unescape reports it as an unknown entity.
What is the difference between ' and '?
They are the same character. ' is one of the five XML predefined entities, while ' is the numeric form that HTML 4 also understands. For XML both are valid, and Unescape reads either.
Do I need to escape text inside a CDATA section?
No. Inside a CDATA section the ampersand and angle brackets are plain characters, except that the sequence ]]> ends the section. Use this page for ordinary text and attribute values, not for the inside of CDATA.
About this tool
Escape replaces & < > " and ' with & < > " and '. Turn off the quote option for element text, where quotes do not need escaping. XML 1.0 forbids most control characters, unpaired surrogates, U+FFFE and U+FFFF, and even an escape cannot make them legal, so the tool reports the first one with its position, or removes them if you choose that. Unescape accepts only the five XML entities and numeric references, and stops on anything else, such as , or a bare &. It does not parse or validate a whole XML document, and CDATA sections are not interpreted.