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 0Java 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.
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url><loc>https://example.com/</loc></url><urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url><loc>https://example.com/</loc></url>
</urlset>Where this bites most
Other XML errors
- Opening and ending tag mismatch
- 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
- 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.