Skip to main content

XML error · InvalidTag

Unclosed tag

The document ended, or a construct swallowed the rest of it, while an element was still open.

Unclosed tag 'urlset'.

What it means

The parser reached the end of the input with an element still waiting to be closed. Sometimes the element really is unclosed; just as often the document was truncated, or an unterminated comment or CDATA section ate everything after it.

This is the signature error of a partial download or a write that was cut short, which is why it is common on large generated sitemaps and feeds.

What usually causes it

  • The file is truncated — an interrupted download, a full disk, or a stream closed early.
  • An unterminated comment: <!-- with no matching -->.
  • An unterminated CDATA section: <![CDATA[ with no matching ]]>.
  • A generator that writes an opening tag then throws before writing the close.
  • A response body cut off by a proxy or gateway timeout.

How to fix it

  • Compare the byte size against Content-Length or the source to confirm truncation.
  • Search for <!-- and <![CDATA[ counts and check each one is closed.
  • Re-fetch the document; transient truncation is common on large files.
  • Make the generator write to a buffer and emit 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.

  • libxml2 (PHP, lxml, Nokogiri)

    Premature end of data in tag urlset line 1
  • Xerces (Java)

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

    no element found: line 3, column 0
  • Go encoding/xml

    unexpected EOF

Before and after

Both snippets are checked on every build: the first is confirmed to produce the 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.