Can't get sitemap.xml file to work

I use the R Studio > Blogdown > Github > Netlify chain to publish my website https://whatbank.ca

I am trying to add a sitemap.xml file by placing it in layouts/sitemap.xml

I saved the file with Save as Encoding > UTF-8

When I point Chrome to whatbank.ca/sitemap.xml I get the error: enter image description here

The rendering of the page is empty.

When I view the Page Source I see:

<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
&lt;?xml version="1.0" encoding="UTF-8"?>

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

   <url>

      <loc>https://whatbank.ca/</loc>

      <lastmod>2005-01-01</lastmod>

      <changefreq>monthly</changefreq>

      <priority>0.8</priority>

   </url>

</urlset> 

Yet the raw source on Github looks like:

<?xml version="1.0" encoding="UTF-8"?>

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

   <url>

      <loc>https://whatbank.ca/</loc>

      <lastmod>2005-01-01</lastmod>

      <changefreq>monthly</changefreq>

      <priority>0.8</priority>

   </url>

</urlset> 

My thinking is that the 2nd line of whatbank.ca/sitemap.xml, &lt;?xml version="1.0" encoding="UTF-8"?> , is rendering the entire file invalid.

Why does the file get changed?
Is this the correct approach to add a custom sitemap.xml file?

Personally, I add the first line like this: {{- (printf "<?xml version = \"1.0\" encoding=\"UTF-8\"?>") | safeHTML -}}

Strangely, it still doubles the first line:

<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<?xml version = "1.0" encoding="UTF-8"?><urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">

Hi there,

Please have a read about Requesting Help to see how to make it easier for us to help you. We cannot help you if we cannot reproduce your issue.

It works in my sample here

own sitemap templates!

check config / Output

[outputs]
home = [ “HTML”, “ATOM”, “JSON”, “FEED”, “MANIFEST”, “SITEMAP”]
section = [ “HTML”, “SITEMAP” ]

to activate sitemaps

Templates are in the theme dir under layouts/_default

You are free to copy it, it you like it :wink: