all things Sitecore related

Linq to Xml: Generate Google Sitemap with sitemap-protocol

By on July 8, 2009 in ASP.Net, Google, linq, XML with 1 Comment

In this example I will generate a XML site-map that complies with the sitemap-protocol XML schema.

//create datasource

List<string> blogPosts = new List<string>{

//Create namespace for sitemap-protocol

XNamespace xmlNS = "";
XDocument xmlDoc =
 new XDocument(
  new XDeclaration("1.0", "UTF-8", null),
  new XElement(xmlNS + "urlset",
   from blogPostUrl in blogPosts
    new XElement(xmlNS + "url",
    new XElement(xmlNS + "loc", blogPostUrl))

//Show output


This example will give the following output:

<urlset xmlns="<a href=""></a>">

To keep the example as simple as possible I only use the LOC element of the URL node. In the real world you can implement the lastmod, changefreq and priority node.

More information about the sitemap-protocol.

About the Author

About the Author: Pieter is Technical Marketing Manager for Sitecore Netherlands and owner of He has more than ten years experience with software developing in multiple programming languages and with different Content Management Systems. Before joining Sitecore Pieter was a lead developer for multiple Sitecore and .Net projects, he joined Sitecore in 2011 as an Solution Architect in The Netherlands, after two years as an Solution Architect he joined the Technical Marketing department. In the role as Techinical Marketing Manager he is responsible for the Global MVP program and the Sitecore technical branding strategy. You can follow Pieter on twitter: @pieterbrink123 or Google+ .


If you enjoyed this article, subscribe now to receive more just like it.

There is 1 Brilliant Comment

Trackback URL | Comments RSS Feed

  1. That’s great, I never thought about Generate Google Sitemap with sitemap-protocol like that before.

Post a Comment

Your email address will not be published. Required fields are marked *