XML Sitemaps

Although XML Sitemaps are written only for web spiders, they are easy to create. They are collections of links with their respective (optional) attributes formatted according to the XML schema.

At the time of this writing, XML Sitemap Protocol is at version 0.9 (as signified by its schema version). You must save each XML Sitemap file using the UTF-8 encoding format. Other rules apply as well. If you are familiar with XML, these rules should be easy to understand.

XML Sitemap Format

Each link in an XML Sitemap can have up to four attributes. The first attribute, loc, is the URL location and is mandatory. The rest of the attributes are optional and include lastmod, changefreq, and priority. Here is an example Sitemap file with a single link:

<?xml version='1.0' encoding='UTF-8'?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9
        http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">

   <url>
      <loc>http://mydomain.com/</loc>
      <lastmod>2010-01-01</lastmod>
      <changefreq>weekly</changefreq>
      <priority>0.5</priority>
   </url>

</urlset>

In this example, we can see the XML file header which describes the rules that this XML document is bound to. Note that the XML header would need to change only if you wanted to support the upgraded schema.

The next (bolded) section represents a single URL entry enclosed by <url> tags. Within this block we see all of the possible ...

Get SEO Warrior now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.