XML Sitemap Generation and Submission Guide

An XML sitemap (sitemap.xml) is a file that lists your site's URLs for search engines, helping crawlers discover new and updated pages faster — especially valuable for large sites, deep hierarchies, or sparse internal linking. It won't directly boost rankings, but it significantly improves crawl and index efficiency in SEO optimization. Based on the sitemaps.org protocol and official Google Search Central documentation, this guide covers generation, format, and submission best practices.

XML Format and Tags

A standard XML sitemap uses <urlset> as the root element, with one <url> entry per page. <loc> is required; <lastmod>, <changefreq>, and <priority> are optional:

<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
  <url>
    <loc>https://www.example.com/foo.html</loc>
    <lastmod>2026-08-01</lastmod>
  </url>
</urlset>

Three things to keep in mind: Google ignores <priority> and <changefreq> values, so writing them won't affect crawl priority; <lastmod> should accurately reflect the date of the last significant update — a sloppy value can actually mislead crawlers; and special characters in URLs (such as & and ?) must be entity-escaped, e.g. & becomes &amp;. The file must be UTF-8 encoded.

Also, use the W3C date format for <lastmod> (e.g. 2026-08-01); if you need time-level precision you can include a timezone, e.g. 2026-08-01T10:30:00+08:00 — an invalid format makes Google ignore the field entirely.

Size Limits and Sitemap Index Files

A single sitemap can contain at most 50,000 URLs and must not exceed 50MB (uncompressed). Beyond that, split your URLs into multiple sitemaps and manage them with a <sitemapindex> file:

<?xml version="1.0" encoding="UTF-8"?>
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
  <sitemap>
    <loc>https://www.example.com/sitemap-posts.xml</loc>
    <lastmod>2026-08-01</lastmod>
  </sitemap>
  <sitemap>
    <loc>https://www.example.com/sitemap-products.xml</loc>
  </sitemap>
</sitemapindex>

A sitemap may only list URLs from the same host, and URLs must be absolute (including protocol and domain). Splitting by content type (posts, products, categories) is a common practice that also makes ongoing maintenance easier.

How to Generate: From Scripts to Plugins

  • CMS auto-generation: WordPress, Wix, and others generate sitemaps automatically or via plugins (e.g. Yoast SEO, Rank Math) that update as content changes.
  • Manual creation: fine for sites with very few URLs, but easy to forget to update.
  • Script generation: for dozens of URLs or more, generate programmatically from your database, e.g. with Python:
import xml.sax.saxutils as sax

urls = ["https://www.example.com/foo.html", "https://www.example.com/bar.html"]
lines = ['<?xml version="1.0" encoding="UTF-8"?>',
         '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">']
for u in urls:
    lines.append(f"  <url><loc>{sax.escape(u)}</loc></url>")
lines.append("</urlset>")
open("sitemap.xml", "w", encoding="utf-8").write("\n".join(lines))

Keep sitemaps in sync with actual pages; see the website indexation guide for the full crawl pipeline.

How to Submit

  1. Google Search Console: submit in the Sitemaps report to view crawl status and processing errors; see the Google Search Console tutorial.
  2. robots.txt: add Sitemap: https://example.com/sitemap.xml to your robots.txt; see the robots.txt configuration guide.
  3. HTTP ping: some search engines support a ping endpoint to notify them of updates — for example Bing's IndexNow, which can notify participating engines after a single call and suits sites without GSC; Baidu's webmaster tools offer similar active push.

Multilingual and Media Sitemaps

For multilingual sites, maintain a separate sitemap per language and annotate language versions with hreflang at the page level, so URLs in different languages don't compete in search results. Image sites can nest <image:image> tags inside <url> to provide image URLs, titles, and license info; video sites use <video:video> for thumbnails, duration, and player URLs. These extensions follow their own XML namespaces, with documentation from both Google and Bing.

A common misconception: a sitemap only solves the "discovery" problem, not the "quality" problem. Duplicate content that search engines keep filtering and worthless parameter pages won't help no matter how many times they're listed — they may even drain your crawl budget. Do content cleanup first, then let the sitemap reflect a clean, crawl-worthy list.

Common Errors and Troubleshooting

Error Meaning Fix
Couldn't fetch Pages return 4xx/5xx Check URLs and status codes
Couldn't read File format or encoding issue Validate the XML
Sitemap is empty Contains no URLs Confirm <url> entries
Includes noindex pages Conflicts with meta robots Remove or correct
Malformed Unescaped chars or bad root Repair the XML structure

Best Practices

  • List only canonical URLs in your sitemap; avoid duplicate or parameterized pages — see the canonical and duplicate content guide.
  • Promptly remove deleted or redirected URLs.
  • Submitting a sitemap is only a hint and doesn't guarantee crawling; after launching a new site, actively request indexing via the URL Inspection tool.
  • Keep lastmod fresh so crawlers can identify content freshness. Image and video sites can further supplement media assets with Image/Video sitemaps.

Order also matters: put your most important, frequently updated pages near the top of the file so crawlers prioritize them; keep the URL count lean instead of padding it with hundreds of low-traffic tag pages. A healthy sitemap tells search engines "this site deserves more crawl budget."

FAQ

How often should I update it? If content changes frequently, refresh lastmod and regenerate after each publish; for rarely updated sites, stay in sync with the publishing workflow.
Does submitting guarantee indexing? No. A sitemap is only a hint — whether pages get crawled ultimately depends on page quality and site authority.
Do multilingual sites need separate sitemaps? You can annotate language versions with hreflang, or maintain an independent sitemap per language, keeping URLs absolute and non-duplicated.

Source: https://developers.google.com/search/docs/crawling-indexing/sitemaps/build-sitemap, protocol spec at https://www.sitemaps.org/protocol.html