DEV Community

adithyasrinivasan
adithyasrinivasan

Posted on • Originally published at adithya.dev on

XML Sitemap is rendering as plain text

After adding <xhtml:link> to my sitemap file where I included <xhtml:link rel="alternate" hreflang="supported_language-code"> my XML sitemap file started rendering as a plain text file.

In the console window of Chrome, I saw an error as well which indicated the structure was off.

Caught TypeError: Cannot read properties of null (reading 'childNodes')at XMLDocument.ready (content.js:218)ready @ content.js:218
Enter fullscreen mode Exit fullscreen mode

I had to adjust my <urlset> from this

<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml">

Enter fullscreen mode Exit fullscreen mode

to this, thanks to this Stackoverflow answer

<urlset 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 http://www.w3.org/TR/xhtml11/xhtml11_schema.html http://www.w3.org/2002/08/xhtml/xhtml1-strict.xsd"
        xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
        xmlns:xhtml="http://www.w3.org/TR/xhtml11/xhtml11_schema.html">
Enter fullscreen mode Exit fullscreen mode

Strangely enough that while the XML was rendering properly, Google Search Console was displaying an issue for the sitemap

Your Sitemap or Sitemap index file does not properly declare the namespace!

Enter fullscreen mode Exit fullscreen mode

The schema below fixed the Google issue (that's all we care about in 2021, right?) while the rendering issue still persists.

<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        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">
Enter fullscreen mode Exit fullscreen mode

Discussion (0)