Tools

Home
JSON FormatterSQL FormatterJS ValidatorMinify CSS
Merge PDFCompress PDFImage to PDF
JPG to PNGPNG to WebPCrop Image

XML Entity Encoder

Escape and unescape XML special characters and entities — supports named, decimal, and hexadecimal entities

Your files never leave your browser
Input0 chars, 0 lines
Output0 chars, 0 lines
Ready·

Paste raw text or XML and instantly convert the five reserved characters — &, <, >, ", ' — into safe entity references, or decode encoded entities back to plain text. Supports named, decimal, and hex formats.

And everything runs in your browser. Nothing gets uploaded.

How It Works

Paste Text or XML
→
Encode or Decode
→
Safe XML Output

The encoder scans your text character by character. When it hits one of the five reserved XML characters (&, <, >, ", '), it swaps it for the matching entity reference. Decoding works in reverse — it finds entity patterns and converts them back to the original characters. Numeric entities (decimal and hex) are supported as well.

Examples

Company name in an XML field

You need to store "AT&T" inside an XML element without breaking the parser.

INPUT
AT&T Corporation
OUTPUT
AT&amp;T Corporation

HTML snippet inside XML data

Storing an HTML fragment as a text value in an XML config file. The angle brackets in the HTML tags would confuse the XML parser if left raw.

INPUT
<p class="note">Price < $50</p>
OUTPUT
&lt;p class=&quot;note&quot;&gt;Price &lt; $50&lt;/p&gt;

Decoding a SOAP response

You received a SOAP API response where the message body is entity-encoded. Tough to read as-is.

INPUT
&lt;error&gt;Value can&apos;t be &lt; 0&lt;/error&gt;
OUTPUT
<error>Value can't be < 0</error>

Who Uses This

👨‍💻 Developers

Escaping user input before inserting it into XML configs, SOAP payloads, or RSS feeds.

🔌 API Engineers

Debugging encoded SOAP responses and decoding entity-heavy XML messages from third-party services.

📝 Technical Writers

Preparing code samples that include angle brackets or ampersands for XML-based documentation formats like DITA.

🔍 QA Testers

Checking if special characters in test data break XML parsing or get double-encoded by the application.

Common Mistakes

Double-encoding entities

Running the encoder twice turns &amp; into &amp;amp;. If your text already has XML entities in it, decode first, then re-encode once. Check the output for patterns like &amp;amp; or &amp;lt; — those are a dead giveaway.

Only escaping ampersands but ignoring quotes

People remember & needs escaping but forget about " and ' inside attribute values. An unescaped quote in name="O'Brien" will break the attribute boundary and corrupt your document. This tool catches all five reserved characters.

Encoding entire XML documents instead of just text content

If you encode a whole XML file, the tags get escaped too — <root> becomes &lt;root&gt;. Only encode the text values going inside elements or attributes, not the structural markup itself.

Technical Details

Frequently Asked Questions

What are XML entities and why do I need to encode them?

XML reserves five characters for its own syntax: &, <, >, ", and '. If these show up in your data — say, a product name with an ampersand — the parser treats them as markup instead of text. Encoding replaces them with safe references like &amp; so the parser reads them correctly.

What is the difference between XML encoding and HTML encoding?

XML only defines five named entities (&amp; &lt; &gt; &quot; &apos;). HTML defines over 250 — things like &nbsp;, &copy;, and &mdash;. An XML parser will reject &nbsp; unless you declare it in a DTD. If you are working with XML specifically, stick to the five built-in entities plus numeric references.

Can I use CDATA sections instead of encoding?

CDATA sections (<![CDATA[ ... ]]>) tell the parser to treat everything inside as plain text. The catch: CDATA can't appear in attribute values, and the text itself cannot contain ]]>. For attribute values and short strings, entity encoding is more reliable. CDATA works better for large blocks of embedded code or HTML.

How do I fix double-encoded XML?

Double-encoding looks like &amp;amp; or &amp;lt; — entities wrapped in more entities. Paste your text into the decoder and run it once. If you still see entity references in the output, decode again. Repeat until the text looks clean, then encode exactly once for your final XML.

Is it safe to paste sensitive XML data into this tool?

Yes. The encoding and decoding happen entirely in JavaScript inside your browser tab. No data is sent to a server — there are zero network requests involved. You can disconnect from the internet and the tool still works fine. Your text stays on your machine from start to finish.

Share: