'<', hexadecimal value 0x3C, is an invalid attribute character

A literal < inside an attribute value.

The message, as .NET reports it
'<', hexadecimal value 0x3C, is an invalid attribute character. Line 1, position 15.

Why it happens

  • A comparison or HTML snippet written into an attribute as is, usually by string concatenation.

How to fix it

Write &lt; instead of <, or build the XML with XmlWriter or XElement, which escape it.

.NET throws an XmlSchemaValidationException at the first schema error unless XmlReaderSettings.ValidationEventHandler is set, which then receives every one with its line and position. A well-formedness error is an XmlException and ends reading whatever the settings.

The same problem in xmlvalid

xmlvalid validates with libxml2, which reports it as Unescaped '<' not allowed in attributes values. It checks the whole document in your browser and lists every schema error with its line and column, not only the first.

Unescaped '<' not allowed in attributes values

Example

Reports the error
<rule test="a < b"/>
Fixed
<rule test="a &lt; b"/>