Sitemap.xml file changed between Github and Live

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

When I point Chrome to whatbank.ca/sitemap.xml I get the error:

When I view 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"
      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">



<url>
  <loc>https://www.whatbank.ca/</loc>
  <lastmod>2021-03-25T13:24:33+00:00</lastmod>
</url>


</urlset>

Yet the source on Github looks like:

<? xml version="1.0" encoding="UTF-8" ?>
<urlset
      xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
      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">
<!-- created with Free Online Sitemap Generator www.xml-sitemaps.com -->


<url>
  <loc>https://www.whatbank.ca/</loc>
  <lastmod>2021-03-25T13:24:33+00:00</lastmod>
</url>


</urlset>

I’m suspicious of the second line on the live version of sitemap.xml
&lt;?xml version="1.0" encoding="UTF-8"?>

Is that the reason why my browser ignores the XML file?
Why is this happening?

My guess is that it’s being ignored because it’s not valid XML. First, there is the encoded < symbol, which throws an error, but if you fix that, there you get the error that only one <?xml> command is allowed per file.

Agreed. But the sitemap.xml file on Github does look like valid HTML. Correct? Somehow when Netlify pulls the file and publishes it, the sitemap.xml file gets corrupted. Do you think that is what is happening?

It would seem so, but if the sitemap file is already good to go, it should be possible to transfer it without any processing from GitHub to Netlify. That depends on your build process.

I just push the files from my local machine to Github and then Netlify automatically pulls them and makes the site live. I’m not sure how to get a file to be part of my site without placing it on Github.

I tried the sitemap.xml file at sitemaps.org - Protocol and I still end up with the second line duplicated and corrupted. “<?xml version=“1.0” encoding=“UTF-8”?>”

I wondered whether it has anything to do with character encoding. I tried Save with Encoding > UTF-8 and there was no difference.

I’m stumped.

Hey there @lawmalroomcom :wave:

It looks like this thread has been quiet for a few days. Are you still experiencing this issue? What additional steps have you tried since you last posted? Let us know, and I can bring this to the Support Team.