</>
ValidateHTML

Unescaped Special Characters in XML

XML reserves several characters for its syntax: & (starts entity references), < (starts tags), and > (ends tags). When these characters appear in text content or attribute values, they must be replaced with their entity references: &amp; for &, &lt; for <, and &gt; for >. Failing to escape them confuses the parser.

Why It Matters

A single unescaped & or < in text content causes the XML parser to misinterpret the structure. It may try to read the text as a tag or entity reference, producing cryptic error messages. The entire document becomes unparseable.

Code Examples

Invalid XML
<?xml version="1.0" encoding="UTF-8"?>
<company>
  <name>Smith & Sons</name>
  <motto>We make price < competition</motto>
  <code>if (x > 0 && y < 10)</code>
</company>
Valid XML
<?xml version="1.0" encoding="UTF-8"?>
<company>
  <name>Smith &amp; Sons</name>
  <motto>We make price &lt; competition</motto>
  <code>if (x &gt; 0 &amp;&amp; y &lt; 10)</code>
</company>

How to Fix

  • 1Replace & with &amp; in all text content and attribute values.
  • 2Replace < with &lt; and > with &gt; when they appear in text, not as tag delimiters.
  • 3For large blocks of text with many special characters, use a CDATA section: <![CDATA[...]]>.
  • 4Also escape " as &quot; and ' as &apos; inside attribute values when needed.

Check Your XML Now

Our XML validator detects this error automatically and shows the exact line and column.

Open XML Validator
Recommended

Hostinger Fast & Affordable Web Hosting

Serve well-formed XML feeds and APIs on reliable hosting.

Get 80% Off Hosting →

Related XML Errors

View all XML errors