5

Generating a Sitemap with multiple languages:

Following Google instructions from:

https://support.google.com/webmasters/answer/189077?hl=en

THIS CODE:

<?xml version="1.0" encoding="UTF-8"?>
  <urlset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">
  <url>
    <loc>https://www.example.com</loc>
    <lastmod>${formattedDate}</lastmod>
    <changefreq>daily</changefreq>
    <priority>1.0</priority>
  </url>
</urlset>

RESULTS IN (RENDERED IN THE BROWSER):

enter image description here

THIS CODE (WITH THE xhtml:link TAGS):

<?xml version="1.0" encoding="UTF-8"?>
  <urlset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">
  <url>
    <loc>https://www.example.com</loc>
    <lastmod>${formattedDate}</lastmod>
    <changefreq>daily</changefreq>
    <priority>1.0</priority>
    <xhtml:link rel="alternate" hreflang="en-us" href="https://www.example.com"/>
    <xhtml:link rel="alternate" hreflang="en-ca" href="https://ca.example.com"/>
    <xhtml:link rel="alternate" hreflang="en-gb" href="https://uk.example.com"/>
  </url>
</urlset>

RESULTS IN (RENDERED IN THE BROWSER):

enter image description here


QUESTION

There does not seem to be any errors. But it's weird that it doesn't render the XML "page" as usual in the browser.

This https://www.google.com/gmail/sitemap.xml from Google also seems to have the same behavior (you can inspect it and see that the response contains a bunch of xhtml:link tags).

Am I doing anything wrong or is it the normal behavior when you add those xhtml:link tags?

cbdeveloper
  • 27,898
  • 37
  • 155
  • 336
  • See a similar question https://stackoverflow.com/questions/36193346/validation-of-xml-sitemap-urlset-with-xhtmllink-inside-url-element – Farandole Sep 13 '20 at 16:39
  • The sitemap is valid, that's what matters. Remember the XML sitemaps are intended for robots and not humans, a human would appreciate an nicely styled HTML sitemap. – Ismail Sep 19 '20 at 15:58

0 Answers0