On this page
A successful sitemap request only tells you that the server returned a response. It does not prove that the body is valid XML, that the listed URLs work, or that search engines can index them. Use this checklist before a content release to inspect the sitemap and its pages separately.
Key Takeaways
- Check the sitemap’s HTTP response, then parse its body as XML; these are separate tests.
- Confirm whether the file is a sitemap of pages or a sitemap index containing other sitemap files.
- Review listed URLs for the intended hostname, escaping, stale entries, redirects, and errors.
- Check representative pages for indexability signals, including canonical URLs and indexing directives. A page returning 200 is not an indexing guarantee.
This checklist could not be checked against Google Search Central or the Sitemap protocol documentation in this environment. Consult those sources before relying on it for complete protocol limits or search-engine-specific requirements. The examples below were not executed here.
1. Check the sitemap response and body
Request the sitemap with GET, replacing the example URL with your own:
curl -sS --compressed --max-time 30 \
-D sitemap.headers \
-o sitemap.xml \
-w 'HTTP status: %{http_code}\n' \
'https://www.example.com/sitemap.xml'
Review sitemap.headers and the reported status. A 200 is a starting point, not a validation result. Also check that:
- The response body is the intended sitemap, not a login page, error template, or HTML page returned with status 200.
- The content type and encoding are consistent with the returned file. The XML parser in the next step checks the body; the content type alone does not prove it is XML.
- If the sitemap URL redirects, inspect the
Locationheader and request the destination separately. Confirm that the final URL is the one you intend to publish. - The downloaded file is complete and reasonable in size for your site. If it appears truncated, investigate the server or download before interpreting parser errors.
Treat the downloaded file as untrusted input. The Python example below is intended for a sitemap you control, not as a public XML-processing service; impose file-size and resource limits before processing arbitrary uploads.
Advertisement
2. Parse the XML and inspect the listed URLs
A page sitemap normally has a urlset root containing url entries. A sitemap index has a sitemapindex root containing sitemap entries; its locations point to other sitemap files, not directly to the pages you want to sample.
Save the following as check_sitemap.py. It uses Python’s standard library to parse a local file and screen locations for a few common mistakes. It is not a complete sitemap schema or protocol validator.
import sys
import xml.etree.ElementTree as ET
from urllib.parse import urlsplit
NS = "http://www.sitemaps.org/schemas/sitemap/0.9"
def tag(name):
return f"{{{NS}}}{name}"
def main():
if len(sys.argv) != 3:
print("Usage: python3 check_sitemap.py FILE EXPECTED_HOST", file=sys.stderr)
return 2
filename, expected_host = sys.argv[1], sys.argv[2].lower()
try:
root = ET.parse(filename).getroot()
except (ET.ParseError, OSError) as exc:
print(f"Could not parse sitemap: {exc}", file=sys.stderr)
return 1
if root.tag == tag("urlset"):
entry_tag = tag("url")
kind = "page sitemap"
elif root.tag == tag("sitemapindex"):
entry_tag = tag("sitemap")
kind = "sitemap index"
else:
print("Unexpected root element or sitemap namespace", file=sys.stderr)
return 1
entries = root.findall(entry_tag)
print(f"Parsed {kind}; entries found: {len(entries)}")
problems = 0
if not entries:
print("Review: no entries found")
problems += 1
seen = set()
for number, entry in enumerate(entries, start=1):
locations = entry.findall(tag("loc"))
if len(locations) != 1 or locations[0].text is None:
print(f"Entry {number}: expected one nonempty loc")
problems += 1
continue
loc = locations[0].text.strip()
try:
parts = urlsplit(loc)
host = parts.hostname
# Accessing port also detects some malformed port values.
_ = parts.port
invalid = (
not loc
or any(ch.isspace() for ch in loc)
or parts.scheme.lower() not in ("http", "https")
or not host
or host.lower() != expected_host
or parts.username is not None
or parts.password is not None
or bool(parts.fragment)
)
except ValueError:
invalid = True
if invalid:
print(f"Entry {number}: review location {loc!r}")
problems += 1
if loc in seen:
print(f"Entry {number}: duplicate location {loc!r}")
problems += 1
seen.add(loc)
print(f"Items flagged for review: {problems}")
return 1 if problems else 0
if __name__ == "__main__":
sys.exit(main())
Run it with the hostname you expect in this file:
python3 check_sitemap.py sitemap.xml www.example.com
The hostname comparison is an intentionally strict release check, not a statement that every sitemap deployment must use this exact arrangement. Review any intentional exceptions against the applicable sitemap and search-engine guidance. The script does not verify URL length limits, all allowed XML elements, URL reachability, or indexability. A zero exit status only means its limited checks found no problems.
For a sitemap index, repeat the response and XML checks for each child sitemap. Check the pages listed in those child files separately. If there are many files or URLs, automate the inventory and sample deliberately rather than assuming a successfully parsed index validates its children.
Check XML escaping and URL encoding
An ampersand separating query parameters must be escaped in XML. For example, a location can contain:
<loc>https://www.example.com/search?q=tea&sort=asc</loc>
The XML parser reads & as an ampersand in the URL. Do not replace it with a literal & in the XML file; that can make the document malformed. Conversely, XML escaping is not the same as URL percent-encoding: characters that belong in a URL but need URL encoding must be handled as part of constructing the URL. Avoid double-encoding already encoded paths or query values.
Advertisement
3. Validate representative page URLs separately
Choose samples from each child sitemap and major page type, including newly published pages, recently removed or moved pages, and URLs with non-ASCII characters, percent-encoded paths, or query parameters. Sampling is useful for release checks, but it cannot establish that every listed URL works. For a larger inventory, schedule an authorized crawl of all listed URLs with appropriate rate limits.
Request each sample without automatically following redirects:
curl -sS --compressed --max-time 30 \
-D page.headers \
-o page.html \
-w 'HTTP status: %{http_code}\n' \
'https://www.example.com/sample-page'
Inspect page.headers and page.html:
- Status: Look for page URLs returning client or server errors even though the sitemap itself returned 200. A 200 page can still be an error page or otherwise unsuitable for indexing, so inspect the body too.
- Redirects: If a listed page redirects, inspect its
Locationand request the destination. Update the sitemap to the intended final canonical URL when appropriate; investigate redirect chains or loops. - Hostname and scheme: Confirm that the URL belongs to the intended site and environment, not a staging host, outdated domain, or unintended scheme.
- Content and freshness: Compare the page with your release inventory. Remove stale entries for deleted content or update entries when content has moved.
- Indexability signals: Inspect the page’s canonical link, robots meta directives, and relevant response headers such as
X-Robots-Tag. Check the applicablerobots.txtrules as well. A redirect, canonical pointing elsewhere,noindexdirective, or crawl restriction can change how a search engine treats the page.
GET is useful here because it lets you inspect both headers and content. A HEAD request can be a quick supplementary check, but do not assume every server handles HEAD identically to GET.
These checks identify signals and failures; they do not guarantee that a search engine will crawl or index a page. For important releases, also review your search engine’s site diagnostics and indexing reports after deployment.
Common Mistakes
- Treating the sitemap’s 200 response as proof of valid XML. Parse the downloaded body, and check that it is the intended sitemap.
- Checking only the sitemap index. Fetch and inspect its child sitemaps, then check their page URLs.
- Following redirects automatically without reviewing them. Record the original status and destination so stale sitemap entries remain visible.
- Testing only the homepage or a few new pages. Include moved, deleted, parameterized, and differently templated pages in the sample.
- Assuming valid XML means valid or indexable URLs. Parsing does not check page responses, canonical choices, or indexing directives.
- Publishing literal ampersands in XML query strings. Escape them as
&while keeping URL encoding distinct from XML escaping.
Best Practices
- Generate sitemap entries from the same release inventory used to publish and retire content, then compare the resulting locations with that inventory.
- Prefer intended canonical page URLs and investigate unexpected hosts, duplicates, errors, and redirects before release.
- Automate parsing and URL checks in a controlled environment, with timeouts, rate limits, and alerts for failures. Do not expose a checker that fetches arbitrary submitted URLs without appropriate network and destination safeguards.
- Recheck the deployed sitemap and representative pages after release; a local file check cannot detect deployment or server configuration errors.
Conclusion
Validate the sitemap response, parse the XML, and test the listed pages as separate steps. Each catches a different class of release problem, and none alone proves that every page will be indexed.
What would your domain sell for?
A free TidyURLs account unlocks the Domain Estimator. It prices a name from 191,011 real domain sales.