XML error · syntax
Invalid element name
An element name breaks XML's naming rules — usually because it starts with a digit, contains a space, or uses punctuation XML reserves.
StartTag: invalid element name (line 2)What it means
XML names must begin with a letter or underscore, then may contain letters, digits, hyphens, underscores and periods. A leading digit, a space, or most punctuation is invalid.
This is the classic failure of generating element names from data: column headers, JSON keys and year labels become names XML will not accept.
What usually causes it
- Element names generated from data: <2026-total>, <1st-quarter>.
- A space or slash in a generated name.
- Names starting with the reserved sequence xml, in any case.
- A character that is legal in a JSON key but not in an XML name.
How to fix it
- Prefix generated names so they start with a letter or underscore: <y2026-total>.
- Replace illegal characters when mapping data to names.
- Better still, keep the element name fixed and put the variable part in an attribute: <total period="2026"/>.
The same error elsewhere
Different parsers, same defect. If you arrived with one of these messages, you are in the right place.
Xerces (Java)
Element type "2026-total" must be followed by either attribute specifications, ">" or "/>".expat (Python)
not well-formed (invalid token): line 2, column 3.NET System.Xml
Name cannot begin with the '2' character.
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.
<report>
<2026-total>1200</2026-total>
</report><report>
<total period="2026">1200</total>
</report>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)
- Document is empty
- Unsupported encoding
- Sequence ']]>' not allowed in content
- Comment not terminated
- Detected an entity reference loop
- PCDATA invalid Char value (control character)
- Unescaped '<' in an attribute value
- 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.