XML error · InvalidTag
Tag is an invalid name
An element name breaks XML's naming rules — usually because it starts with a digit.
Tag '2026-total' is an invalid name.What it means
XML names must begin with a letter or underscore and may then contain letters, digits, hyphens, underscores and periods. A leading digit, a space, or most punctuation is invalid.
This is the classic failure of generating XML element names from data — column headers, JSON keys, or year labels become element names that 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 name containing a character that is legal in JSON keys but not in XML names.
How to fix it
- Prefix generated names so they start with a letter or underscore: <y2026-total>.
- Replace illegal characters with hyphens or underscores when mapping data to names.
- Better still, put the variable part in an attribute and keep the element name fixed: <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.
libxml2 (PHP, lxml, Nokogiri)
StartTag: invalid element nameXerces (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 checked on every build: the first is confirmed to produce the 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
- Expected closing tag
- Unclosed tag
- Closing tag has not been opened
- Character is not expected
- Start tag expected
- XML declaration allowed only at the start of the document
- Attribute is without value (unquoted attribute value)
- Attribute is repeated
- Attributes have open quote
- Invalid tags found (open elements at end of input)
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.