Unescaped Less-Than Sign in XML – Fix < in Text

Local only

A literal less-than sign cannot appear directly in XML character data because < begins markup such as an element, comment, or processing instruction.

32 chars · 1 line

Waiting for input

Loading XML parser…

XML character escaping

How to fix an unescaped less-than sign in XML text

The sample uses < as ordinary comparison text inside message. XML reserves that character to start markup, so literal data must encode it as &lt; or place appropriate text in a CDATA section when that better fits the source. This tool is free to use. No account or payment is required.

Last updated

What you can do here

  • XML well-formedness validation
  • Broken XML example preloaded
  • Corrected XML comparison
  • .xml file import
  • Browser parser feedback
  • Browser-local processing

Steps

  1. Find the less-than sign inside text near the parser error.
  2. Confirm that it represents data rather than the beginning of an XML tag.
  3. Replace the literal character with &lt; and validate again.

Less-than is reserved because it begins XML markup

When a parser sees < in ordinary character data it expects valid markup to follow. A comparison expression or prose fragment therefore needs escaping if the symbol is part of the text value.

CDATA can be useful for larger markup-like text blocks

CDATA sections can hold many characters that would otherwise look like markup, but they have their own closing delimiter and should be used intentionally rather than as a blanket replacement for ordinary escaping.

Less-than sign in XML character data

Encode the comparison symbol without changing the message value.

Invalid XML

<message>value < limit</message>

Corrected XML

<message>value &lt; limit</message>

Common questions

Frequently asked questions

How do I write < as text in XML?

Use &lt; when the less-than character is data rather than markup.

Does > always need escaping in XML text?

Not in ordinary text in the same way < does, though escaping it as &gt; can still be useful in some contexts.

Can CDATA contain literal < characters?

Yes. CDATA is designed for text that would otherwise contain markup-like characters, subject to its own ]]> delimiter rule.

Debugging a specific XML issue? Browse XML troubleshooting.