XML · July 28, 2026 · 8 min

How to Escape XML Characters Online

Complete guide to escaping XML special characters: & < > " '. Free online XML entity encoder reference.

Which Characters Must Be Escaped?

XML requires escaping five special characters when they appear as literal text in element content or attribute values: ampersand (&), less-than (<), greater-than (>), double quote ("), and single quote ('). Each maps to a predefined entity reference.

The entity references are &amp; for &, &lt; for <, &gt; for >, &quot; for ", and &apos; for '. XML parsers interpret these sequences as single characters when reading document content.

Failing to escape breaks document structure. A product description containing Price < $50 makes the parser think a new tag starts at <. Escaping produces Price &lt; $50, which displays correctly as literal text.

How to Escape XML Online

Paste your text into QuickFormat's Escape XML Online tool or the XML Escape page. Select Escape mode and click Run. Special characters convert to entity references instantly.

To reverse the process — for example when reading escaped content from logs — switch to Unescape mode. The tool converts &lt; back to < and similar entities back to their original characters.

All processing runs in your browser. Sensitive integration payloads and internal message content never upload to external servers.

Escape Content, Not Structure

A common mistake is escaping entire XML documents. Escaping structural tags converts <catalog> to &lt;catalog&gt;, which is no longer valid XML — it becomes plain text.

Escape only the dynamic text values you insert into templates: user names, product descriptions, error messages, and attribute values containing quotes. Leave element tags and document structure unescaped.

For large blocks of text with many special characters, consider CDATA sections (<![CDATA[...]]>) when your schema allows them. CDATA tells the parser to treat content as raw text without entity processing.

Escaping in Programming Languages

Production systems should escape programmatically at the boundary where untrusted text enters XML. Java offers StringEscapeUtils from Apache Commons, C# has SecurityElement.Escape, Python has xml.sax.saxutils.escape, and Node.js has xml-escape packages.

Use the online tool for quick debugging, testing escape round-trips, and preparing sample data for documentation. Pair it with the XML Formatter to beautify documents and XML to JSON when migrating formats.

Visit the XML Tools hub for all XML utilities in one place, including formatting, escaping, and conversion.

Related Tools

Related Articles