XML error · attribute
Error parsing attribute name
A start tag was never closed with >, so the parser kept reading and found the next element's markup where an attribute name should have been.
error parsing attribute name (line 2)What it means
Having read an element name, the parser expects either an attribute, a > or a />. A < instead means the previous tag was never finished, and what follows is being read as though it belonged to it.
The reported position is where the parser gave up, which is the start of the next tag rather than the tag that is actually broken. The fault is immediately before it.
What usually causes it
- A missing > on a start tag, usually after hand-editing attributes.
- A stray < inside an attribute value that was not escaped as <.
- Concatenated template fragments where one contributed the opening angle bracket and another the attributes.
- An attribute name containing a character XML does not allow in names.
How to fix it
- Close the tag before it: check the element on the preceding line ends with > or />.
- Escape any literal < inside attribute values as <.
- Build markup with a serializer rather than string concatenation, so tags are always balanced.
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 "root" must be followed by either attribute specifications, ">" or "/>".expat (Python)
not well-formed (invalid token): line 2, column 5.NET System.Xml
The '<' character, hexadecimal value 0x3C, cannot be included in a name.
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.
<?xml version="1.0"?>
<root<child/></root><?xml version="1.0"?>
<root><child/></root>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)
- Invalid element name
- 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
- 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.