Arpan Shah
Arpan Shah

Reputation: 25

Incorrect namespace in Sitemap

I am getting this error on google search console. I tried bunch of things but nothing worked. Any suggestion if i am missing something.

Description: Your Sitemap or Sitemap index file doesn't properly declare the namespace.

Example: Your Sitemap or Sitemap index file doesn't declare the expected namespace: http://www.sitemaps.org/schemas/sitemap/0.9 Tag: urlset

This is what i see on the sitemap:

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

My Code:

public XmlSitemapResult(IEnumerable<ISitemapItem> items)
        {
            _items = items;
        }

        public override void ExecuteResult(ControllerContext context)
        {
            string encoding = context.HttpContext.Response.ContentEncoding.WebName;
            XDocument sitemap = new XDocument(new XDeclaration("1.0", "utf-8", "yes"),
                 new XElement("urlset", new XAttribute(XNamespace.Xmlns.GetName("Xmlns"), "http://www.sitemaps.org/schemas/sitemap/0.9"),
                      from item in _items
                      select CreateItemElement(item)
                      )
                 );

            context.HttpContext.Response.ContentType = "text/xml";
            context.HttpContext.Response.Flush();
            context.HttpContext.Response.Write(sitemap.Declaration + sitemap.ToString());
        }

Upvotes: 0

Views: 4362

Answers (1)

user6932427
user6932427

Reputation:

I think i know what the problem try remove Xmlns from the urlset tag. A sample XML site map:

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

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

   <url>

      <loc>http://www.example.com/</loc>

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

      <changefreq>monthly</changefreq>

      <priority>0.8</priority>

   </url>

</urlset> 

Font: http://www.sitemaps.org/protocol.html

Upvotes: 2

Related Questions