How do you check that an XML sitemap is valid?
Start with the two things every sitemap consumer needs: the file must parse as XML, and its root element must be <urlset> (a list of pages) or <sitemapindex> (a list of other sitemaps). This validator downloads the sitemap from the URL you give it, checks both, and tells you how many entries it found.
That covers the failures that stop a crawler reading the file at all. Deeper rules from the protocol, like URL limits and escaping, are listed further down so you can check them yourself.
Running the validator
- Enter the full sitemap URL, for example
https://www.example.com/sitemap.xml. If you don't know it, look for aSitemap:line in the site's robots.txt. - Click Validate.
- Read the one-line result, or the parser error if the XML is broken.
Our server makes the request, following up to ten redirects, with an eight-second timeout per response and a cap of 10 MB on what it reads. URLs that resolve to private or reserved IP addresses are refused.
Results you'll see
A page sitemap with three entries:
Valid sitemap (<urlset>) with 3 URL(s).
A sitemap index pointing at two child sitemaps:
Valid sitemap index (<sitemapindex>) with 2 sitemap(s).
The failures are more informative. These outputs come from real test files:
| Message | What happened | Fix |
|---|---|---|
That is not valid XML: EntityRef: expecting ';' |
A raw & inside a <loc>, e.g. ?a=1&b=2 |
Escape it as & |
That XML document's root element is <rss>, not <urlset> or <sitemapindex> |
You entered an RSS or Atom feed URL | Use the sitemap URL, or submit the feed to Search Console separately |
The sitemap URL returned HTTP 404, not a sitemap. Check the address. |
The server answered with an error status instead of the file | Open the URL in a browser and check what it actually serves |
The sitemap URL returned an empty response. |
A 200 status with no body, often a misconfigured sitemap plugin | Regenerate the sitemap and check the server serves it |
The <urlset> element declares no namespace; sitemaps must use xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"... |
The root element is missing its xmlns attribute, or uses an old or misspelled namespace |
Add the sitemaps.org namespace exactly as shown |
That is not valid XML: Start tag expected... |
The body isn't XML at all, for example a gzip file sent without a Content-Encoding header | Serve the uncompressed file, or fix the server's headers |
That is not valid XML: Premature end of data in tag loc... |
The file is truncated, for example by a generator that crashed mid-write | Regenerate the file |
That sitemap is larger than 10 MB, so this tool didn't check it fully... |
The file is over this tool's read limit | Split the sitemap, or check it locally |
The parser's message is passed through as-is, so the exact wording comes from libxml, the XML library PHP uses.
What "valid" means here, and what it doesn't
The check is deliberately narrow. A file passes if the URL answers with a 2xx status, the body is well-formed XML, and its root element is urlset or sitemapindex in the http://www.sitemaps.org/schemas/sitemap/0.9 namespace. The count is the number of <url> or <sitemap> elements in that namespace. It doesn't:
- confirm each
<url>has a<loc>; - check that
<lastmod>values are real dates; - fetch any listed URL, or any child sitemap in an index;
- read a gzipped file served without a
Content-Encodingheader.
For a structural check, paste the sitemap and the XSD schema published on sitemaps.org into the XSD validation tool. To read a long sitemap comfortably, run it through the XML formatter.
Protocol rules worth checking by hand
The sitemaps.org protocol and Google's sitemap guide agree on these limits:
- 50,000 URLs or 50 MB uncompressed per file, whichever comes first. Above that, split into several sitemaps and list them in a sitemap index.
- UTF-8 encoding, with ampersands, quotes, apostrophes and angle brackets entity-escaped in every value (
&becomes&, for example). - Absolute URLs. Each
<loc>starts with the protocol, and the protocol says it must be under 2,048 characters. Google asks for fully qualified URLs because it fetches them exactly as written. - Same host and path. Under the protocol, a sitemap at
/catalog/sitemap.xmlmay only list URLs under/catalog/, on the same protocol and host. Google relaxes the path rule for sitemaps submitted through Search Console.
Google's guide also says it ignores <priority> and <changefreq>, and only uses <lastmod> when it's consistently accurate. If your CMS stamps every URL with today's date on each build, that value is noise; better to drop it or tie it to real content changes. Google calls a sitemap a hint, so a valid file still doesn't guarantee crawling.
After the file validates
A parseable sitemap full of dead or redirected URLs still wastes crawl effort. Spot-check a few <loc> values with the redirect checker: every listed URL should answer 200 directly, not through a redirect. Make sure the sitemap is advertised too: a Sitemap: line in robots.txt is enough for crawlers to find it, and the robots.txt generator can add one.
Last updated