Skip to content

XML Encoder

Quote marks
Encoded XML text —
Characters replaced
—
Input characters
—
Output characters
—

An XML encoder replaces the characters that XML treats as markup for their predefined entities: the ampersand becomes &, the angle brackets become < and >, and quotes become " and &apos;. For example, Smith & Sons "Ltd" encodes to Smith & Sons "Ltd", with three characters replaced.

About this tool

A stray ampersand in a product name or a less-than sign in a formula is enough to make an XML parser reject a whole feed, sitemap or config file. This encoder rewrites text so it can sit safely inside an element or an attribute value. It replaces the five characters defined in section 4.6 of the XML 1.0 specification, counts how many of each it changed, and can also turn every character above U+007E into a hexadecimal reference for systems that mangle UTF-8. Control characters that XML 1.0 forbids are removed with a warning. It encodes text only: it does not check that a full document is well-formed, and running it twice encodes the ampersands again.

How to use it

  1. Add the text

    Paste the value into the box or open a .txt or .xml file from your device.

  2. Choose how to treat quotes

    Encode quotes for attribute values; keep them for plain element text.

  3. Decide on non-ASCII

    Tick the checkbox to write accented letters and symbols as references such as é.

  4. Copy the output

    The encoded text and the table of replaced characters update while you type.

Examples

Company name for an attribute

Text to encode
Smith & Sons "Ltd"
Quote marks
Encode quotes
Write non-ASCII as &#x…; references
No

Result Encoded XML text: Smith & Sons "Ltd"
Characters replaced: 3
Input characters: 18
Output characters: 32

  1. Each & becomes & first in the same pass, so existing entities are encoded again rather than skipped.
  2. Quotes are encoded as " and &apos;, safe inside attribute values.
  3. Non-ASCII characters are kept as typed (valid in a UTF-8 document).

The ampersand and both double quotes are replaced, so the name can sit inside name="…" without ending the attribute early.

Element text with an apostrophe

Text to encode
Tom & Jerry's
Quote marks
Keep quotes
Write non-ASCII as &#x…; references
No

Result Encoded XML text: Tom & Jerry's
Characters replaced: 1
Input characters: 13
Output characters: 17

  1. Each & becomes & first in the same pass, so existing entities are encoded again rather than skipped.
  2. Quotes are left as typed, which is valid in element text.
  3. Non-ASCII characters are kept as typed (valid in a UTF-8 document).

In element content only the ampersand must change; the apostrophe is left as typed.

Accents as character references

Text to encode
café €5
Quote marks
Encode quotes
Write non-ASCII as &#x…; references
Yes

Result Encoded XML text: café €5
Characters replaced: 2
Input characters: 7
Output characters: 19

  1. Each & becomes & first in the same pass, so existing entities are encoded again rather than skipped.
  2. Quotes are encoded as " and &apos;, safe inside attribute values.
  3. Characters above U+007E are written as hexadecimal references such as é.

é is U+00E9 and the euro sign is U+20AC, so both become hexadecimal references that survive a non-UTF-8 pipeline.

How it is calculated

& → & · less-than → < · greater-than → > · " → " · ' → &apos; · optional: code point above U+007E → &#xHEX;

& < > " &apos;
the five entities every XML processor recognises without a DTD
&#xHEX;
a character reference giving the Unicode code point in hexadecimal

The text is read one Unicode code point at a time in a single pass, so an ampersand is never encoded twice within one run. The greater-than sign only strictly needs escaping after ]], but encoding it everywhere is harmless and avoids that edge case. Code points that XML 1.0 never permits, such as U+0000 to U+0008, are dropped because no reference can represent them.

When not to use it

  • For text going into HTML, an HTML encoder covers named entities like   that XML does not define.
  • Text that is already encoded will be encoded again, turning & into &amp;.
  • Large blocks of code are often easier to wrap in a CDATA section than to escape character by character.

Common mistakes

  • Keeping raw quotes in a value that will go inside an attribute delimited by the same quote mark.
  • Encoding a whole XML document, tags included, when only the text values needed escaping.
  • Assuming &apos; works in old HTML 4 parsers; it is defined in XML but not in HTML 4.

Frequently asked questions

Which characters must be escaped in XML?

The ampersand and the less-than sign must always be escaped in text. The greater-than sign must be escaped after the sequence ]], and quote marks must be escaped inside an attribute that uses the same quote as its delimiter. This tool escapes all five by default.

Why is the apostrophe written as &apos; and not '?

Both are valid XML. &apos; is one of the five predefined entities, while ' is a numeric reference to the same character. Choose Keep quotes if your target system dislikes &apos;; apostrophes in element text need no escaping at all.

Do I need to encode accented letters?

Not if the document is saved as UTF-8, which is the XML default. References like é help only when the text passes through a system that uses a different encoding or strips bytes above 127.

What happens to control characters?

XML 1.0 forbids most characters below U+0020 apart from tab, line feed and carriage return, even as references. They are removed from the output and a warning reports how many were dropped.

Is this the same as URL encoding?

No. URL encoding uses percent signs, such as %26 for an ampersand, and is meant for addresses. XML encoding uses entities such as & and is meant for document content.

Is my text uploaded?

No. The encoding runs in your browser, and an opened file is read locally on your device without being sent to a server.

Cite this tool

Using this tool in an assignment, article or report? Copy a citation, or a link for your website.

APA

Tools Directory Editorial Team. (2026, October 12). XML Encoder. Tools Directory. Retrieved October 26, 2026, from https://tools.milunir.com/converters/text-encoding/xml-encoder/

MLA

Tools Directory Editorial Team. “XML Encoder.” Tools Directory, 12 Oct. 2026, https://tools.milunir.com/converters/text-encoding/xml-encoder/. Accessed 26 Oct. 2026.

Chicago

Tools Directory Editorial Team. “XML Encoder.” Tools Directory. Last modified October 12, 2026. Accessed October 26, 2026. https://tools.milunir.com/converters/text-encoding/xml-encoder/.

Link<a href="https://tools.milunir.com/converters/text-encoding/xml-encoder/">XML Encoder – Tools Directory</a>