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.
Common Causes
- Putting a raw ampersand in text, for example a company name like Smith & Sons, instead of writing Smith & Sons.
- Embedding code or math containing < and > directly in element content rather than escaping them or wrapping them in CDATA.
- Pasting URLs with query strings, where unescaped & separators between parameters break the parser.
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.
Frequently Asked Questions
Which characters must be escaped in XML?
When should I use CDATA instead of escaping?
Does the greater-than sign always need escaping?
Check Your XML Now
Our XML validator detects this error automatically and shows the exact line and column.
Open XML ValidatorCloudways · Managed Cloud Hosting
Fix this XML error, then deploy on Cloudways managed cloud (AWS, GCP, DigitalOcean).
Free 3-day trial · 30% off 3 months + free site migration with code MIGRATE303
Related XML Errors
Unquoted Attribute Values in XML
Every XML attribute value must be wrapped in quotes. Learn how to fix unquoted attribute errors, with clear side-by-side examples and a quick checklist.
Unclosed Tag in XML
Fix the XML unclosed tag error fast. Learn why every opening tag needs a matching closing tag or a self-closing form, with clear examples you can copy.
Mismatched Tags in XML
XML tag names are case-sensitive. Learn how to fix mismatched opening and closing tags, spot nesting mistakes, and make your XML well-formed once more.