Skip to main content
CalcHive

XML Escape & Unescape

Examples

XML tags with attributes

In:<item name="Books & More">5 < 10</item>
Out:&lt;item name=&quot;Books &amp; More&quot;&gt;5 &lt; 10&l...

Special characters

In:Tom & Jerry's "Adventure" <2024>
Out:Tom &amp; Jerry&apos;s &quot;Adventure&quot; &lt;2024&gt;

CDATA-like content

In:<![CDATA[Hello & World]]>
Out:&lt;![CDATA[Hello &amp; World]]&gt;
Share:

Escape or unescape XML special characters instantly. Converts &, <, >, ", and ' to their XML entity equivalents and vice versa.

How to Use XML Escape & Unescape

  1. Select Escape or Unescape mode.
  2. Paste your XML text in the input area.
  3. The result appears instantly as you type.
  4. Click "Copy" to copy the result to your clipboard.

What is XML Escaping?

XML escaping is the process of replacing special characters with their corresponding XML entity references so that an XML parser can process your document correctly. XML reserves five characters for its own syntax: the ampersand (&), less-than (<), greater-than (>), double quote ("), and single quote/apostrophe ('). When any of these characters appear in text content or attribute values, they must be escaped to prevent the parser from treating them as markup.

How XML Escaping Works

XML defines five predefined entity references to represent its reserved characters. The ampersand becomes &amp;, less-than becomes &lt;, greater-than becomes &gt;, double quote becomes &quot;, and apostrophe becomes &apos;. You can also use numeric character references in decimal (&#60;) or hexadecimal (&#x3C;) form. The unescaping (or resolving) process reverses this, converting entity references back into their original characters. Proper escaping is what makes the difference between a well-formed XML document and one that breaks during parsing.

Common Use Cases

  • Embedding user-generated content in XML documents safely
  • Building SOAP web service request and response bodies
  • Generating XML configuration files like Maven POM or Spring config
  • Creating RSS and Atom feed entries with special characters
  • Preparing SVG content that contains text with reserved characters
  • Serializing data for XML-based APIs and data interchange formats

CDATA Sections vs Entity Escaping

XML offers two approaches for including special characters in your content. Entity escaping replaces each reserved character individually and works everywhere, including inside attribute values. CDATA sections (<![CDATA[ ... ]]>) wrap a block of text and tell the parser to treat everything inside as literal characters, with no escaping needed. CDATA sections are convenient when you have large blocks of text containing many special characters, such as embedded code snippets or mathematical expressions.

However, CDATA sections have limitations. They cannot appear inside attribute values, and the content itself cannot contain the closing sequence ]]>. If your text might contain that sequence, entity escaping is the safer choice. In practice, most applications use entity escaping for short strings and attribute values, while reserving CDATA sections for longer blocks of embedded content like inline scripts or code samples.

For encoding HTML-specific entities, use our HTML Entity Encoder. You can format and validate your XML documents with the XML Formatter, or encode binary data for embedding in XML using the Base64 Encoder.

Frequently Asked Questions

Related Tools

Was this tool helpful?