XML Encoding / Decoding

Encode or decode special characters for use in XML documents

About this tool

XML reserves five characters — &, <, >, " and ' — for markup. If a value you insert into an element or attribute contains one of them unescaped, the parser either fails or silently misreads your document. Entity encoding replaces them with &amp;, &lt;, &gt;, &quot; and &apos; so the content stays data.

This tool escapes text for insertion into XML and decodes text that already contains entities, resolving &amp; last so a value like &amp;lt; is not accidentally turned into markup.

When to use it

  • Building an XML element or attribute value that contains & or angle brackets
  • Decoding a SOAP, RSS or SVG response to see the text as readers see it
  • Checking whether a value was escaped twice before it was stored
  • Preparing content for an XML-based config, feed or integration

Worked example

Input

<tag>Hello & Goodbye</tag>

Output

&lt;tag&gt;Hello &amp; Goodbye&lt;/tag&gt;

The angle brackets become &lt; and &gt; and the ampersand becomes &amp;, so the whole string is inert text inside another document.

Frequently asked questions

Which characters have to be escaped in XML?

& and < must always be escaped in content. > is escaped for safety, and " and ' must be escaped inside attribute values, where the tool applies them so a single output works in both element and attribute context.

Does the decoder handle HTML entities such as &nbsp;?

No. It resolves the five predefined XML entities only, which keeps the round trip predictable. HTML named entities are a different, much larger set.

Does this tool send my text anywhere?

No. Encoding and decoding run entirely in your browser.

Related tools