Sitemap.xml with <xhtml:link rel="alternate" hreflang="" href=""/> for multilanguage does not render properly on browser?
Asked Answered
E

0

6

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?

Elyot answered 6/3, 2020 at 12:51 Comment(2)
See a similar question #36193846Major
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.Ailurophile

© 2022 - 2024 — McMap. All rights reserved.