Name cannot begin with the character

A < in text that does not start a valid tag.

The message, as .NET reports it
Name cannot begin with the ' ' character, hexadecimal value 0x20. Line 1, position 10.

Why it happens

  • A literal < in text, such as a comparison: what follows it is read as a tag name.
  • A tag name starting with a digit, a space or another character names may not start with.

How to fix it

Write &lt; for a literal < in text, or use a CDATA section.

.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 StartTag: invalid element name. It checks the whole document in your browser and lists every schema error with its line and column, not only the first.

StartTag: invalid element name

Example

Reports the error
<expr>a < b</expr>
Fixed
<expr>a &lt; b</expr>