Skip to main content

XML error · syntax

Document is empty

Nothing arrived at all. Almost always a transport problem — a 204, a dropped connection, or a fetch that succeeded against the wrong URL.

Document is empty (line 1)

What it means

The parser was handed zero bytes. This is distinct from "Start tag expected", which means something arrived but was not XML; here there was no content whatsoever.

Because the failure is upstream of the document, nothing about the XML itself is at fault. Reading the document will never explain it — the answer is in the response that produced it.

What usually causes it

  • An HTTP 204, a 304 handled as a 200, or a body consumed twice before parsing.
  • A feed or sitemap endpoint that returns an empty body when it has nothing to publish.
  • A file written but never flushed, or read before the writer closed it.
  • A gzip-encoded response decoded with the wrong content encoding, yielding nothing.
  • A conditional request answered with an empty body because an ETag matched.

How to fix it

  • Log the status code and Content-Length alongside the body before parsing, so the empty case is visible.
  • Treat an empty body as its own outcome rather than as a parse failure — they need different alerts.
  • Check the response was not already read: a stream consumed once is empty the second time.
  • For scheduled fetches, retry once; an empty body is frequently transient.

The same error elsewhere

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

  • Xerces (Java)

    Premature end of file.
  • expat (Python)

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

    EOF
  • .NET System.Xml

    Root element is missing.

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
(an empty document)
Parses
<?xml version="1.0" encoding="UTF-8"?>
<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.