I'm having trouble defining my sitemap to Google's liking. I'm having a hard time testing this, because I can only test the validity of our sitemap using Google Webmaster Tools, when the newest code has been deployed to our production-environment, which can only happen every 3 weeks (every sprint). That is why I am asking here, instead of just testing it myself.

The header of my generated sitemap looks like this (added new-line and indentation for readability):

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

When I test my sitemap in Google Webmaster Tools, it tells me that my namespace is invalid, and I don't understand why.

I've found two articles about it, one from Google, and one from sitemaps.org. The Google's example-header looks like this:

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

and the example from sitemaps.org has this header:

<?xml version='1.0' encoding='UTF-8'?>
xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd"

Mine looks like Google's example, except I have this extra schema include, which was recommended on a third site:


Why is mine invalid? Does the include have to be before the namespace? Should it work without this extra include? Or do I actually need everything from the sitemap.org header-example, and in that order?



Google is (of course) correct. This is what you want:

<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
    -- Additional variables if you want them.

I ended up using code something like this (I'm generating the sitemap in C#):

// Create a variable holding the sitemap namespace
XNamespace sitemapNs = XNamespace.Get("http://www.sitemaps.org/schemas/sitemap/0.9");

// Create a new standalone XDocument
var xDocument = new XDocument(new XDeclaration("1.0", "utf-8", "yes"));

// Create the urlset-element
var xElement = new XElement(sitemapNs + "urlset");

// Create a new url-element and add elements to it
var el = new XElement(sitemapNs + "url");
el.Add(new XElement(sitemapNs + "loc", loc));
el.Add(new XElement(sitemapNs + "changefreq", changeFreq));
el.Add(new XElement(sitemapNs + "priority", priority));
el.Add(new XElement(sitemapNs + "lastmod", lastMod));

// Add the url-element to the urlset-element

// Add the urlset-element to the XDocument

Obviously, I've coded it so I can add several elements easily, and I have separate methods for generation the header and handling the different elements.

1 Answer 1


This is happening because you are using an invalid namespace, the article your followed is outdated and should of never be used. Follow the W3C XML schema recommendation to get rid of these errors removed. More explained about the namespace location.


XML Schema instance namespace See the XML Schema Recommendation for an introduction

$Date: 2001/03/16 20:25:57 $

$Id: XMLSchema-instance.xsd,v 1.4 2001/03/16 20:25:57 ht Exp $

This schema should never be used as such:
                the XML
                Schema Recommendation forbids the declaration of
                attributes in this namespace

Use something like:

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="//example.com/sitemap.xsl"?>
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
  • So I should remove this line? xmlns:xsi="w3.org/2001/XMLSchema-instance" Commented May 18, 2015 at 11:52
  • 1
    Remove it. Use something like in my example (answer edited). Commented May 18, 2015 at 12:02
  • I have added my working code to my question. Commented May 18, 2015 at 13:17
  • Leaving out the lines: xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" and xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd" made several sitemap validators on the web go crazy. Leaving them in, does not seem to affect acceptance with any of the webmaster tools I'm using. Commented Jun 10, 2015 at 7:48

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.