The sitemap.xml file structure

Abstract

Overview of how auto-generated sitemap.xml files are structured in SXA.

SXA auto-generates sitemaps that follow globally approved guidelines. To read more about sitemaps in general, see this Google docs article about sitemaps, and this Google docs article about building and submitting a sitemap.

Sitemap entries have the following elements: loc, lastmod, changefreq, and priority.

Alternate links for different languages

When a sitemap has alternate links for pages in different languages, the links are formatted in the following way:

<url>
    <loc>http://www.example.com/deutsch/</loc>
    <xhtml:link
                 rel="alternate"
                 hreflang="en"
                 href="http://www.example.com/english/" />
     <xhtml:link
                 rel="alternate"
                 hreflang="de-ch"
                 href="http://www.example.com/schweiz-deutsch/" />
     <xhtml:link
                 rel="alternate"
                 hreflang="de"
                 href="http://www.example.com/deutsch/" />
  </url>

To follow the global best practices, SXA follows these general principles:

  • If there are 2 or more languages, there is a separate entry for each language defined in loc.

  • If there are 2 or more languages defined for a page, x-default is set for one hreflang. For example:

    <xhtml:link rel="alternate" hreflang="x-default" href="http://sxa/contact-us"/>
     <xhtml:link rel="alternate" hreflang="en" href="http://sxa/en/contact-us"/>
     <xhtml:link rel="alternate" hreflang="da" href="http://sxa/da/contact-us"/>
    
  • If there is only a single language, SXA lists the language with an href, but does not add the language code under loc.

Example of site structure

The following example uses both English and Danish sites:

<?xml version="1.0" encoding="utf-8" standalone="no"?>
<urlset xmlns:xhtml="http://www.w3.org/1999/xhtml"
    xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
    <url>
        <loc>https://sxa/en</loc>
        <lastmod>2020-07-18</lastmod>
        <changefreq>daily</changefreq>
        <priority>0.5</priority>
        <xhtml:link rel="alternate" hreflang="x-default" href="https://sxa/" />
        <xhtml:link rel="alternate" hreflang="da" href="https://sxa/da" />
        <xhtml:link rel="alternate" hreflang="en" href="https://sxa/en" />
    </url>
    <url>
        <loc>https://sxa/da</loc>
        <lastmod>2020-07-19</lastmod>
        <changefreq>daily</changefreq>
        <priority>0.5</priority>
        <xhtml:link rel="alternate" hreflang="x-default" href="https://sxa/" />
        <xhtml:link rel="alternate" hreflang="da" href="https://sxa/da" />
        <xhtml:link rel="alternate" hreflang="en" href="https://sxa/en" />
    </url>
    <url>
        <loc>https://sxa/page-da</loc>
        <lastmod>2020-07-19</lastmod>
        <changefreq>daily</changefreq>
        <priority>0.5</priority>
        <xhtml:link rel="alternate" hreflang="da" href="https://sxa/da/page-da" />
    </url>
    <url>
        <loc>https://sxa/page-en</loc>
        <lastmod>2020-07-19</lastmod>
        <changefreq>daily</changefreq>
        <priority>0.5</priority>
        <xhtml:link rel="alternate" hreflang="en" href="https://sxa/en/page-en" />
    </url>
    <url>
        <loc>https://sxa/en/page-multi</loc>
        <lastmod>2020-07-19</lastmod>
        <changefreq>daily</changefreq>
        <priority>0.5</priority>
        <xhtml:link rel="alternate" hreflang="x-default" href="https://sxa/page-multi" />
        <xhtml:link rel="alternate" hreflang="da" href="https://sxa/da/page-multi" />
        <xhtml:link rel="alternate" hreflang="en" href="https://sxa/en/page-multi" />
    </url>
    <url>
        <loc>https://sxa/da/page-multi</loc>
        <lastmod>2020-07-19</lastmod>
        <changefreq>daily</changefreq>
        <priority>0.5</priority>
        <xhtml:link rel="alternate" hreflang="x-default" href="https://sxa/page-multi" />
        <xhtml:link rel="alternate" hreflang="da" href="https://sxa/da/page-multi" />
        <xhtml:link rel="alternate" hreflang="en" href="https://sxa/en/page-multi" />
    </url>
</urlset>