XML error · attribute
Unescaped '<' in an attribute value
A literal < inside an attribute value. XML forbids it there because the parser cannot tell it from the start of a tag, so it must be written <.
Unescaped '<' not allowed in attributes values (line 2)What it means
Inside an attribute value, < is the one character that cannot appear literally. The parser reads it as the beginning of a new tag and abandons the attribute it was in the middle of.
The ampersand has the same restriction, but its failure is reported as an entity error instead. Both come from the same place: attribute values are parsed content, not opaque strings.
What usually causes it
- Building XML by string concatenation and escaping only element content, not attributes.
- A comparison or arithmetic expression stored in an attribute: threshold="a < b".
- A generator that HTML-escapes text nodes but passes attribute values through untouched.
- User-supplied input reaching an attribute without escaping — the same gap that produces XML injection.
How to fix it
- Write < for a literal less-than sign inside an attribute value.
- Escape & as & in attributes too — it is invalid there for the same reason.
- Stop concatenating strings and use a serializer, which escapes attribute values correctly by construction.
- Move the value into element content wrapped in CDATA if it is long or expression-like.
The same error elsewhere
Different parsers, same defect. If you arrived with one of these messages, you are in the right place.
Xerces (Java)
The value of attribute "title" must not contain the '<' character.expat (Python)
not well-formed (invalid token): line 2, column 15.NET System.Xml
'<', hexadecimal value 0x3C, is an invalid attribute character.fast-xml-parser and similar
(accepted — no error reported at all)
Before and after
Both snippets are re-checked by the test suite against the real parser: the first is confirmed to produce the exact error above, the second to parse cleanly.
<?xml version="1.0"?>
<root title="a < b"/><?xml version="1.0"?>
<root title="a < b"/>Where this bites most
Other XML errors
- Opening and ending tag mismatch
- Premature end of data in tag
- Extra content at the end of the document
- Unescaped ampersand (EntityRef: expecting ';')
- Entity is not defined
- Start tag expected
- XML declaration allowed only at the start of the document
- Unquoted attribute value (AttValue expected)
- Attribute redefined
- Attributes construct error (unterminated quote)
- Invalid element name
- Document is empty
- Unsupported encoding
- Sequence ']]>' not allowed in content
- Comment not terminated
- Detected an entity reference loop
- PCDATA invalid Char value (control character)
- Invalid numeric character reference
- Blank needed here
- Malformed declaration expecting version
- Unsupported XML version
- Processing instruction not terminated
- CData section not finished
- Error parsing attribute name
- Double hyphen within comment
- CharRef: invalid decimal value
Get started
Bring order to the XML your team can't afford to ignore.
Create a free account and get a private workspace to search, validate, diff, and monitor your XML feeds, sitemaps, schemas, and vendor integrations.