Compare a sitemap with its publication list
On this page
A sitemap returning 200 and parsing correctly does not establish coverage of every intended public page. Save the publication inventory and XML separately, then use set differences to locate candidates before resubmitting files.
JC Chouinard’s first-person sitemap troubleshooting guide emphasizes the actual address, response and XML structure. The following Python script compares a saved XML sitemap with a local publication list.
Prepare two files with matching scope
Export a CSV with a url column from the CMS or publishing process. Include intended public canonical addresses, not every draft or private workflow. Save the corresponding published XML and retrieval date.
If the file is a sitemap index, identify its children and have the owner confirm the merge scope. This script accepts one urlset and performs no recursive network download.
Compare original addresses
Save the inputs as published.csv and sitemap.xml. Save the following script beside them as compare_sitemap.py, then open a terminal in that directory and run python3 compare_sitemap.py:
import csv
import xml.etree.ElementTree as ET
from collections import Counter
ns = '{http://www.sitemaps.org/schemas/sitemap/0.9}'
root = ET.parse('sitemap.xml').getroot()
if root.tag != ns + 'urlset':
raise ValueError('Expected urlset; review sitemap index separately')
rows = []
for number, entry in enumerate(root.findall(ns + 'url'), start=1):
locations = entry.findall(ns + 'loc')
if len(locations) != 1 or not (locations[0].text or '').strip():
raise ValueError(f'Sitemap url entry {number}: expected one non-empty loc')
rows.append(locations[0].text.strip())
with open('published.csv', newline='', encoding='utf-8-sig') as f:
reader = csv.DictReader(f)
if not reader.fieldnames or 'url' not in reader.fieldnames:
raise ValueError('published.csv: expected a url column')
published = set()
for number, record in enumerate(reader, start=2):
value = (record.get('url') or '').strip()
if not value:
raise ValueError(f'published.csv row {number}: empty url')
published.add(value)
listed = set(rows)
print('duplicates', sorted(u for u, n in Counter(rows).items() if n > 1))
print('missing', sorted(published - listed))
print('unexpected', sorted(listed - published))Protocol, host, case, parameters and trailing slashes remain intact. Exact-string differences may require a URL-policy decision; automatic normalization can conceal them.
Check the output on a small sample
In the teaching fixture, publication rows are A, B, C, D and sitemap rows are A, B, B, E. Expect duplicate B, missing C and D, and unexpected E.
Also test a missing loc, an empty loc and an empty CSV URL field separately. Expect an entry or row error, not three empty lists. The sitemap protocol requires loc in each url. These checks verify input completeness, not full protocol validity. CSV parsers skip blank records; use a quoted empty value, "", when testing an empty field.
This does not establish that Google never discovered C or D, or that E should be removed. The inventory may omit E; C may be intentionally excluded. Have owners resolve purpose before changing generation inputs.
| Difference | Investigation | Possible treatment |
|---|---|---|
| Published but unlisted | Purpose, indexing policy and generation condition | Repair inventory or generator according to policy |
| Listed but absent from inventory | Historical page, move or inventory scope | Establish facts before deciding |
| Duplicate entry | Repeated concatenation or address variants | Repair generation and verify |
| XML parse failure | HTML response or truncated file | Preserve delivery evidence |
Google’s sitemap overview describes a discovery mechanism, not an indexing guarantee.
Verify generation rather than a one-time edit
Save file versions, differences and owner decisions. Repair the source, regenerate and rerun the same comparison. Check downloads, language versions and intentional exclusions.
This verifies inventory relationships. Use URL Inspection for present access and indexed evidence.