Webmaster Bench

Tools / Guides / XML sitemap errors: how to find and fix them

XML sitemap errors: how to find and fix them

Most sitemap problems come from a handful of mistakes in the XML. Here is each one, what the specification says, and a broken sitemap run through the validator and fixed.

Published 2026-11-17. Last updated 2026-11-17. Written by Webmaster Bench; see About for how the guides are made and checked.

Try it: XML Sitemap Validator: Validate a sitemap or sitemap index against the protocol and Google's rules; build one from a URL list.

The mistakes, from most to least damaging

1. An unescaped ampersand makes the whole file unreadable

A sitemap is an XML file, and in XML a bare & starts an entity. The sitemaps.org protocol says that data values, including URLs, "must use entity escape codes" for five characters:

CharacterWrite it as
& ampersand&
' single quote'
" double quote"
> greater than>
< less than&lt;

Google's documentation says the same in fewer words: "all tag values must be entity escaped". The ampersand is the one you will meet most, because query strings contain it. This sitemap has one bare ampersand:

<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
  <url><loc>https://www.example.com/shoes?color=red&size=9</loc></url>
</urlset>

Pasted into the validator, it reports: "The XML is not well-formed, so search engines cannot read any of it", followed by the XML parser's own message and a hint that an unescaped & was found and must be written as &amp; inside <loc>. The parser's wording differs between browsers, so the validator adds that hint. This is a fatal error: it is one character in one URL, and the file is unusable. Fix: color=red&amp;size=9. Note that &amp; is only how the URL is written in the file; the URL itself still has a single &.

This happens when XML is built by joining strings. If you write the file by hand, or from a script, escape each URL before inserting it. The validator's "Build a sitemap" box does this for you when you paste a plain list of URLs.

2. A missing or wrong namespace

The protocol requires the file to open with a <urlset> tag that declares the namespace http://www.sitemaps.org/schemas/sitemap/0.9. Two easy slips are leaving out the xmlns attribute, or typing https in it. A sitemap index uses the same namespace on <sitemapindex>.

3. URLs that are not absolute

Each <loc> must start with the protocol. Google: "Use fully-qualified, absolute URLs in your sitemaps." A relative path such as /boots is not acceptable. Each value must also be under 2,048 characters (sitemaps.org), and, as with any XML text, saved as UTF-8.

4. A lastmod that is not a W3C date

The protocol says <lastmod> uses the W3C Datetime format, and that the time part can be left out. These are valid: 2026-11-16 and 2026-11-16T09:30:00+00:00. These are not: 2026-11-16 09:30 (a space instead of T, and no time zone) and 16/11/2026. A template that prints a locale date produces the second kind.

The value also has to be true. The protocol says it is the date the linked page was last modified, not the date the sitemap was generated. Google says it uses lastmod "if it's consistently and verifiably" accurate, and that it should reflect "the last significant update to the page"; changing a copyright year does not count. A sitemap that stamps every URL with the date it was generated gives Google nothing it can verify.

5. URLs from the wrong place

The protocol says a sitemap can only list URLs under its own directory path, and that URLs on a different protocol or host are dropped. Google adds that, unless the sitemap is submitted through Search Console, it only affects descendants of its parent directory, so the root is the safest place. Mixing http://example.com into a sitemap for https://www.example.com is therefore a mistake even though every URL is well formed. List the canonical URL of each page, the one you want in search results.

6. The limits

A single sitemap holds at most 50,000 URLs and is at most 50 MB uncompressed (52,428,800 bytes). Past that, split the sitemap and list the parts in a sitemap index.

Not a mistake, but useless

Google states that it ignores <priority> and <changefreq>. They do no harm; do not spend effort tuning them for Google.

Advertisement

Worked example

This sitemap has the escaping right but still has three kinds of problems:

<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
  <url><loc>https://www.example.com/shoes?color=red&amp;size=9</loc><lastmod>2026-11-16 09:30</lastmod></url>
  <url><loc>/boots</loc><lastmod>16/11/2026</lastmod></url>
  <url><loc>http://example.com/hats</loc><lastmod>2026-11-16</lastmod></url>
</urlset>

The validator's findings, as produced by running this exact text through it:

  • Error: Entry 1: <lastmod> "2026-11-16 09:30" is not a W3C Datetime (e.g. 2024-05-31 or 2024-05-31T14:20:00+00:00).
  • Error: Entry 2: <loc> "/boots" is not an absolute http(s) URL.
  • Error: Entry 2: <lastmod> "16/11/2026" is not a W3C Datetime (e.g. 2024-05-31 or 2024-05-31T14:20:00+00:00).
  • Warning: URLs span 2 origins (https://www.example.com, http://example.com). A sitemap may only list URLs of the site it is hosted on, unless cross-site submission is verified in Search Console. http and https, or www and non-www, count as different.

The fixed file: a W3C datetime with T and a zone, an absolute URL, and the same canonical origin everywhere.

<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
  <url><loc>https://www.example.com/shoes?color=red&amp;size=9</loc><lastmod>2026-11-16T09:30:00+00:00</lastmod></url>
  <url><loc>https://www.example.com/boots</loc><lastmod>2026-11-16</lastmod></url>
  <url><loc>https://www.example.com/hats</loc><lastmod>2026-11-16</lastmod></url>
</urlset>

The validator reports no errors or warnings for the fixed file.

If Search Console says it could not fetch the sitemap

That is a different problem from the ones above: the file could not be retrieved, so no XML check can fix it, and a validator that works on pasted text cannot see it. Open the sitemap's address in a private window and confirm that it returns the XML and not an HTML page or an error, then validate the text you see.

Sources

Advertisement