Skip to main content

XML error · structure

Premature end of data in tag

The document ended while one or more elements were still open — almost always truncation, not an authoring mistake.

Premature end of data in tag urlset line 1 (line 2)

What it means

The parser reached the end of the input with elements still waiting to be closed. It names the outermost one and the line it was opened on.

A document written correctly does not usually lose its closing tags, so this is the signature of a partial write or a truncated transfer rather than a typo. An unterminated comment or CDATA section produces it too, by swallowing the rest of the file.

What usually causes it

  • The file is truncated — an interrupted download, a full disk, or a stream closed early.
  • A response body cut short by a proxy or gateway timeout, or a response-size limit.
  • An unterminated comment (<!-- with no -->) or CDATA section (<![CDATA[ with no ]]>).
  • A generator that writes an opening tag then throws before writing the close.
  • A gzip stream that ended early and decompressed partially.

How to fix it

  • Compare the received byte count against Content-Length or the source file.
  • Count <!-- and <![CDATA[ occurrences and check each one is closed.
  • Re-fetch: transient truncation is common on large sitemaps and feeds.
  • Make generators write to a buffer and publish only on success, so partial output never ships.

The same error elsewhere

Different parsers, same defect. If you arrived with one of these messages, you are in the right place.

  • Xerces (Java)

    XML document structures must start and end within the same entity.
  • expat (Python)

    no element found: line 3, column 0
  • Java SAX / JAXP

    Reached end of file while parsing.
  • Go encoding/xml

    unexpected EOF
  • .NET System.Xml

    Unexpected end of file has occurred. The following elements are not closed: urlset.

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
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
  <url><loc>https://example.com/</loc></url>
Parses
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
  <url><loc>https://example.com/</loc></url>
</urlset>

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.