0

I am using Sitecore 10.2 with sxa. I used default Sitecore sxa setting to generate Sitemap.xml but I see it generates as html and not as xml. Though I see the xml only in view source of sitemap.xml page.

Does anybody know if there is any setting in Sitecore with which I can generate Sitemap as xml or do I need to write custom code?

Thanks :)

1
  • 1
    Your browser is converting to html to make it readable to you. If you view the source and it shows as XML, then its XML. SXA only generates an XML sitemap, you would have to customize it to turn it into html.
    – Richard Seal
    Commented Feb 7, 2023 at 16:55

3 Answers 3

1

With SXA, by default, the sitemap is generated for the whole site and stored in the cache. in the Sitemap Mode field, select the storage option Stored in file for the sitemap.

This sitemap file is stored in the root folder of your server and is usually named sitemap.xml.

That's all you don't need any customization or any other settings to be changed to generate sitemap.xml.

Reference link: https://doc.sitecore.com/xp/en/developers/sxa/102/sitecore-experience-accelerator/configure-a-sitemap.html

1

You can configure the Sitemap XML for the SXA Site in the Settings item under the Site item.

The configurations available can be found in the Search Engines Sitemap section of the Settings item.

enter image description here

You get three options under Sitemap Mode.

  1. Inactive

    Choosing this option will disable the Sitemap for the site.

  2. Stored in cache This option will save the Sitemap file generated in the cache. This option may be used if you are using Azure environments to host your Sitecore instance.

  3. Stored in file This option is recommended if your site is not going to change very often.

You can choose to include externals sitemaps as Key-Value pairs as well.

Also, you can have the Sitemap Index instead of the Sitemap.

The Robots.txt file will have a link to the Sitemap XML file by default.

Hope this helps.

1

As per the Sitecore documentation SXA generates the sitemap according to the XML sitemap format, but the logic for parsing this XML relies on your browser.

You might therefore notice that there are no XML tags displayed in the browser for your sitemap.xml. If you want to display the original XML in your browser, you can install an extension.

Refer this document for more details.

https://doc.sitecore.com/xp/en/developers/sxa/19/sitecore-experience-accelerator/configure-a-sitemap.html

On the other way, if this doesn't resolve your issue then there is a very easy way to customize it.

  1. Create a class named CustomSitemapGenerator.cs

    public class CustomSitemapGenerator : Sitecore.XA.Feature.SiteMetadata.Sitemap.SitemapGenerator
    {
       public CustomSitemapGenerator() : base()
       {
    
       }
       public CustomSitemapGenerator(XmlWriterSettings xmlWriterSettings) : base(xmlWriterSettings)
       {
    
       }
       public override string GenerateSitemap(Item homeItem, SitemapLinkOptions sitemapLinkOptions)
       {
          return GenerateSitemap(homeItem, null, sitemapLinkOptions);
       }
       public override string GenerateSitemap(Item homeItem, NameValueCollection externalSitemaps, SitemapLinkOptions sitemapLinkOptions)
       {
         // Custom logic goes here
       }
    }
    
  2. Create a config file named Feature.SitemapExtension.Sitemap.config

    <?xml version="1.0" encoding="utf-8" ?>
    <configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
    <sitecore>
        <services>
          <register
                   serviceType="Sitecore.XA.Feature.SiteMetadata.Sitemap.ISitemapGenerator, Sitecore.XA.Feature.SiteMetadata"          implementationType="Feature.SitemapExtension.Services.CustomSitemapGenerator, Feature.SitemapExtension" lifetime="Transient"          patch:instead="register[@implementationType='Sitecore.XA.Feature.SiteMetadata.Sitemap.SitemapGenerator, Sitecore.XA.Feature.SiteMetadata']"/>
        </services>
    </sitecore>
    </configuration>
    

Refer this for more details.

https://www.vinayjadav.com/posts/customize-sxa-10-sitemap

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.