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"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
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'?>
<urlset
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"
xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
Mine looks like Google's example, except I have this extra schema include, which was recommended on a third site:
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
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?
Thanks!
SOLUTION
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">
<url>
<loc>some.url.com</loc>
-- Additional variables if you want them.
</url>
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
xElement.Add(el);
// Add the urlset-element to the XDocument
xDocument.Add(xElement);
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.