Skip to main content

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 &lt;.
  • 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 &lt;.
  • 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.

Fails
<?xml version="1.0"?>
<root<child/></root>
Parses
<?xml version="1.0"?>
<root><child/></root>

Where this bites most

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.