Question

I have a website that contains a sitemap.xml file. Currently, my sitemap.xml file looks like the following:

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

<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
  <url>
    <loc>http://www.mysite.com/about/blog/post-1</loc>
    <lastmod>2013-08-13</lastmod>
    <changefreq>never</changefreq>
    <blog:title>This is the title of the blog post</blog:title>
    <blog:description>This is the description of the blog post</blog:description>
    <blog:author>Some person</blog:author>
    <blog:authorUrl>https://www.mysite.com/people/some-person</blog:authorUrl>    
  </url>
</urlset>

As my snippet above shows, I'm trying to extend my sitemap. I'm using the approach detailed at sitemaps.org in the extending the sitemaps protocol section.

I've created an .xsd file called blog.xsd. That file is located at http://www.mysite.com/data/blog.xsd. That file looks like the following:

<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:simpleType name="title">
    <xs:restriction base="xs:string" />
  </xs:simpleType>

  <xs:simpleType name="description">
    <xs:restriction base="xs:string" />
  </xs:simpleType>

  <xs:simpleType name="author">
    <xs:restriction base="xs:string" />
  </xs:simpleType>

  <xs:simpleType name="authorUrl">
    <xs:restriction base="xs:string" />
  </xs:simpleType>  
</xs:schema>

I am trying to figure out how to reference blog.xsd in my sitemap file. Currently, the Google webmaster tool flags my sitemap.xml with warnings. My warning says: "This tag was not recognized. Please fix it and resubmit.". The warning is in reference to the title, description, author, and authorUrl tags. I suspect this is because my sitemap.xml file does not reference blog.xsd. However, I do not know how to do that. Can someone please provide an example? The documentation on sitemaps.org is not very clear. Thank you!

Was it helpful?

Solution

My tip is to read up on XML and namespaces in general; it will help you understand topics like this better.

As you can see in the sitemap documentation you can extend a sitemap with your own elements in their own namespace. You are missing one crucial part in your xml: although you used the namespace prefix blog: on your elements, you never declared a namespace prefix blog.

In the sitemap documentation you see:

<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"
     xmlns:example="http://www.example.com/schemas/example_schema"> <!-- namespace extension -->

It is this last part, xmlns:example="http://www.example.com/schemas/example_schema" that is crucial.

You need to come up with a namespace uri for your blog prefix. It only has to look like a URL, it doesn't actually need to exist. Let's use http://www.mysite.com/data/blog/1.0 - you can use anything else as well.

Then your sitemap becomes:

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

<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" 
        xmlns:blog="http://www.mysite.com/data/blog/1.0">
  <url>
    <loc>http://www.mysite.com/about/blog/post-1</loc>
    <lastmod>2013-08-13</lastmod>
    <changefreq>never</changefreq>
    <blog:title>This is the title of the blog post</blog:title>
    <blog:description>This is the description of the blog post</blog:description>
    <blog:author>Some person</blog:author>
    <blog:authorUrl>https://www.mysite.com/people/some-person</blog:authorUrl>    
  </url>
</urlset>

That should be enough, according to the sitemap documentation.

If you also want to be able to validate the sitemap XML using an XML Schema validator, you can change the <urlset to:

<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" 
        xmlns:blog="http://www.mysite.com/data/blog/1.0"
        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
                            http://www.mysite.com/data/blog/1.0 
                            http://www.mysite.com/data/blog.xsd">
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top