XML Sitemap Structure and Syntax
You'll learn the exact XML format, required elements, and optional attributes that make up a valid sitemap file for search engines.
The Basic XML Structure
An XML sitemap is a structured text file that lists your site's URLs in a specific format that search engines can read. Think of it as a table of contents written in a language Google, Bing, and other crawlers understand perfectly.
Every XML sitemap starts with an XML declaration and a root <urlset> element that defines the namespace:
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<!-- URLs go here -->
</urlset>
Required URL Elements
Each page on your site is wrapped in a <url> tag with one required child element:
<url>
<loc>https://www.example.com/page</loc>
</url>
The <loc> (location) tag contains the full, absolute URL of the page. This is the only mandatory element per URL entry.
Optional Metadata
You can add hints to help search engines prioritize and schedule crawls:
<url>
<loc>https://www.example.com/page</loc>
<lastmod>2024-01-15</lastmod>
<changefreq>weekly</changefreq>
<priority>0.8</priority>
</url>
<lastmod>: Last modification date (YYYY-MM-DD format)<changefreq>: How often the page changes (daily, weekly, monthly, etc.) – this is just a hint, not a command<priority>: Relative importance (0.0 to 1.0) compared to other pages on your site, not the entire web
Note: Search engines use these as suggestions, not strict rules. Google largely ignores changefreq and priority nowadays, but lastmod can still be useful.
Key Takeaway: An XML sitemap follows a strict structure with <urlset> wrapping multiple <url> entries, each containing a required <loc> and optional <lastmod>, <changefreq>, and <priority> tags.