XML Entity & CDATA Escaper
Escape/unescape special XML characters, wrap/unwrap CDATA blocks, and minify XML markup.
Client-Side Execution & Privacy Guarantee
This utility executes 100% locally in your web browser. Your inputs, tokens, queries, and data payloads are never transmitted to any external server or backend.
XML requires that the characters less-than, ampersand, and in certain contexts greater-than, double-quote, and apostrophe be represented by entity references or character references so they are not mistaken for markup. The escaper converts between literal text and the safe forms required inside element content or attribute values.
CDATA sections provide an alternative that lets literal less-than and ampersand appear without entities, but they cannot contain the sequence ]]> and cannot be nested. The tool can wrap a fragment in CDATA, unwrap an existing section, or minify an entire document by removing insignificant whitespace.
The five predefined entities
The XML specification defines five predefined entities: lt for less-than, gt for greater-than, amp for ampersand, quot for double-quote, and apos for apostrophe. In element content both less-than and ampersand must always be escaped; greater-than must be escaped when it appears in the sequence ]]> so that the parser does not treat it as the end of a CDATA section.
Inside attribute values the rules depend on the delimiter. When the attribute is quoted with double-quote, every double-quote must become the quot entity; when quoted with apostrophe, every apostrophe must become the apos entity. The other three characters still require escaping regardless of delimiter.
CDATA sections
A CDATA section begins with the marker less-than exclamation bracket CDATA bracket and ends with bracket bracket greater-than. Inside it the characters less-than and ampersand are treated as ordinary text and entity references are not expanded. The only forbidden sequence is the terminator itself. To include the terminator you must close the section, emit the characters as text or entities, and open a new section.
CDATA is convenient for embedding source code or markup fragments, but it does not protect against the terminator sequence and cannot appear inside attribute values. The tool detects an existing CDATA wrapper and can remove it, restoring the literal content.
Minification
Minification removes whitespace that is insignificant according to the XML rules: whitespace between elements is discarded while whitespace inside text nodes that contain non-whitespace characters is preserved. Comments and processing instructions are left untouched unless you explicitly request their removal.
The operation is purely syntactic; it does not validate against a schema or alter character data beyond the whitespace rules. The result is still well-formed if the input was well-formed.
When to use this tool
- You need to embed literal XML or HTML inside another XML document without breaking the outer parse.
- You are preparing attribute values that contain quotes or angle brackets.
- You want to wrap a code fragment in CDATA for readability inside a configuration file.
- You received an escaped fragment and need to recover the original text.
- You need a compact version of an XML document for transmission or storage.
How to use the XML Entity & CDATA Escaper
- Paste the text or XML fragment into the input area.
- Choose Escape to convert special characters to entities, Unescape to reverse the process, Wrap CDATA, Unwrap CDATA, or Minify.
- For attribute-specific escaping, select the delimiter style if the tool offers the option.
- Click the corresponding action button. The transformed text appears in the output pane.
- Copy the result. If you wrapped CDATA, verify that the content does not contain the sequence ]]>.
- For minification, confirm that significant whitespace inside text nodes has been retained.
- Re-process the output with the opposite operation to verify round-trip fidelity.
Worked examples
Escape element content
if (a < b && c > d)
if (a < b && c > d)
Both less-than and ampersand are escaped; greater-than is also escaped for safety.
Wrap in CDATA
function test() { return x < 10 && y > 5; }
<![CDATA[function test() { return x < 10 && y > 5; }]]>
The CDATA wrapper allows the comparison operators to appear literally.
Common mistakes and tips
- Never place the sequence ]]> inside a CDATA section; split the section or escape the greater-than as an entity outside CDATA.
- In attributes, match the escaping to the quote character you actually use; mixing them produces well-formed but surprising results.
- Unescaping does not interpret numeric character references beyond the five predefined entities unless the tool explicitly expands them.
- Minification can change the string-value of elements that contain only whitespace; preserve such elements if their emptiness is significant.
- Always validate the final document after escaping or wrapping; a missed ampersand or an unclosed CDATA section will make the whole document malformed.
Frequently asked questions
Why is greater-than sometimes left unescaped?
The specification requires escaping of greater-than only when it would form the CDATA terminator. Many tools escape it unconditionally for simplicity and safety.
Can CDATA sections be nested?
No. The first ]]> ends the section. To embed one CDATA inside another you must close and reopen.
Does minification remove comments?
By default comments are preserved. A separate option may strip them if you need the smallest possible document.
Are numeric character references supported?
Unescaping recognizes the five predefined entities. Numeric references such as ampersand hash 60 semicolon are left unchanged unless an explicit expand option is selected.
Is the tool safe for untrusted input?
Escaping prevents the five special characters from being interpreted as markup. It does not sanitize against other XML attacks such as external entity expansion; those require a secure parser configuration.