Skip to main content

XML error · syntax

Start tag expected

What arrived is not XML — an HTML error page, a JSON body, or plain text served under an XML content type. The parser found no opening tag.

Start tag expected, '<' not found (line 1)

What it means

The parser found no start tag where the document should begin, because the content does not start with "<" at all. In practice the response is not XML: a JSON body, a plain-text error, or a stack trace served with an XML content type. An entirely empty body reports "Document is empty" instead.

When this appears for a URL that works in a browser, the usual cause is that the server returns something different to a non-browser client — a bot check, a login wall, or a geo redirect.

Worth knowing what does not land here: a tidy HTML error page is frequently well-formed XML. It parses cleanly and then fails on its root element being <html> rather than what you expected, which is a different problem with a different fix.

What usually causes it

  • A JSON response from an endpoint expected to serve XML.
  • A plain-text error or stack trace returned with an XML media type.
  • A bot-protection challenge served to anything without browser headers.
  • A gzip-compressed body read without decompressing.
  • An empty response body — reported as "Document is empty".

How to fix it

  • Fetch with curl and look at the first bytes of the real body, not the browser's rendering.
  • Check the status code and Content-Type before parsing.
  • Decompress .gz sitemaps before validation.
  • If a bot check intercepts, allowlist the crawler or fetch server-side.

The same error elsewhere

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

  • Xerces (Java)

    Content is not allowed in prolog.
  • expat (Python)

    syntax error: line 1, column 0
  • .NET System.Xml

    Data at the root level is invalid. Line 1, position 1.
  • Go encoding/xml

    expected element type <urlset> but have <html>

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
{"error":"not_found","status":404}
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.