Incorrect namespace in Sitemap
Asked Answered
S

1

0

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());
        }
Sheehan answered 10/10, 2016 at 17:32 Comment(1)
Do you already tried to change sitemaps.org/schemas/sitemap/0.9 to google.com/schemas/sitemap/0.9?Fickle
F
2

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

Fickle answered 10/10, 2016 at 18:41 Comment(3)
Yes, that's it.Fickle
Okay i will git it a shot. so make it like this right? <urlset xmlns="sitemaps.org/schemas/sitemap/0.9">Sheehan
I edited my first post and added one sample. I believe it is necessary "http: // www. "Fickle

© 2022 - 2024 — McMap. All rights reserved.