XML error reference · XV007

Invalid character in element or attribute name

A name uses a character XML does not allow, or starts with one it does not allow.

What your parser calls it

The same problem, reported differently by each parser. If you arrived here from one of these strings, you are in the right place.

ParserMessage
libxml2 / xmllintStartTag: invalid element name
.NET XmlExceptionName cannot begin with the '2' character
Java SAXParserElement type "2024-report" must be followed by either attribute specifications, ">" or "/>".

What causes it

XML restricts names to the NameStartChar and NameChar productions of the specification. A name may begin with a letter, an underscore or a colon, but not with a digit, a hyphen or a period. After the first character, digits, hyphens and periods are allowed. Spaces and the characters `#`, `$`, `@`, `%`, `/` and `+` are never allowed anywhere in a name. Names beginning with the three letters "xml" in any case combination are reserved by the specification.

See it happen

Triggers the error
<2024-report>
  <total amount$="10"/>
</2024-report>
Corrected
<report year="2024">
  <total amount="10"/>
</report>

How to fix it

Rename the element or attribute. When names are generated from data, and CSV column headers or JSON keys are the usual culprits, sanitise them first: prefix a leading digit with an underscore, and replace illegal characters rather than stripping them, so distinct source names stay distinct.

Fix your own document

Paste your own document below. Press Sample if you want the broken example above loaded instead. Nothing you paste leaves this tab.

XML Validator

Well-formedness and schema validation. Nothing is uploaded.

Input
WaitingPaste a document to check it. Validation runs as you type.

Everything runs in this tab. Nothing you paste is uploaded, logged or sent anywhere. Open your network panel and check.

Tools that catch this

Background reading

Errors this fixes

Every XML error, explained