Mobile app version of vmapp.org
Login or Join
Si4351233

: Google Webmaster Tools complains about invalid namespace in my sitemap I'm having trouble defining my sitemap to Google's liking. I'm having a hard time testing this, because I can only test

@Si4351233

Posted in: #Google #Sitemap #Xml

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 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.

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Si4351233

1 Comments

Sorted by latest first Latest Oldest Best

 

@Radia820

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.


SOURCE

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">

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme