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: & for &, < for <, and > 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
<?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>
<?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>
How to Fix
- 1Replace & with & in all text content and attribute values.
- 2Replace < with < and > with > 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 " and ' as ' 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 ValidatorHostinger — Fast & Affordable Web Hosting
Serve well-formed XML feeds and APIs on reliable hosting.
Related XML Errors
Unquoted Attribute Values in XML
All XML attribute values must be enclosed in quotes. Learn how to fix unquoted attribute errors.
Unclosed Tag in XML
Learn why XML throws an unclosed tag error and how to fix it. Every opening tag must have a matching closing tag or be self-closing.
Mismatched Tags in XML
XML tag names are case-sensitive. Learn how to fix mismatched opening and closing tags in XML documents.