Explanation:
This Tutorial is Continiuation of our Tutorial
Create a Dynamic google SiteMap
Here we have simple Google Sitemap with only three informations "Location" ,
"Lastmod" and "Priority"
.
The google xml sitemap ( map.xml ) look like this;
<?xml version="1.0" encoding="utf-8"?>
<urlset xmlns="http://www.google.com/schemas/sitemap/0.84">
<url>
<loc>http://www.dotnet-friends.com</loc>
<lastmod>2006-06-23T21:19:54+00:00</lastmod>
<priority>0.6</priority>
</url>
<url>
<loc>http://www.dotnet-friends.com/Tutorials/tut1.aspx</loc>
<lastmod>2006-06-23T21:19:54+00:00</lastmod>
<priority>0.5</priority>
</url>
<url>
<loc>http://www.dotnet-friends.com/Tutorials/tut2.aspx</loc>
<lastmod>2006-06-23T21:19:54+00:00</lastmod>
<priority>0.5</priority>
</url>
</urlset>
Now we made a simple function which inserts a new Node in the above XML File.
protected void WriteGoogleMapEntry(string PagePath)
{
XmlDocument doc = new XmlDocument();
string path = Server.MapPath("~/map.xml");
doc.Load(path);
XmlDocumentFragment docFrag = doc.CreateDocumentFragment();
docFrag.InnerXml = "<dummy xmlns='http://www.google.com/schemas/sitemap/0.84\'><url><loc>http://www.dotnet-friends.com/"
+
PagePath + "</loc><lastmod>" + DateTime.Now.ToString("yyyy-MM-dd")
+ "</lastmod></url></dummy>";
doc.DocumentElement.AppendChild(docFrag.FirstChild.FirstChild);
doc.Save(Server.MapPath("~/map.xml"));
}
Here PagePath is relative path for the newly created Page. We Created a
"dummy" node to wrap the newly created page. This dummy
node have the same "xmlns" attribute as the root
node. let us consider our passed page relative address look like this "Tutorials/CSharp/tut3.aspx" now the SiteMap will
look like this;
<?xml version="1.0" encoding="utf-8"?>
<urlset xmlns="http://www.google.com/schemas/sitemap/0.84">
<url>
<loc>http://www.dotnet-friends.com</loc>
<lastmod>2006-06-23T21:19:54+00:00</lastmod>
<priority>0.6</priority>
</url>
<url>
<loc>http://www.dotnet-friends.com/Tutorials/tut1.aspx</loc>
<lastmod>2006-06-23T21:19:54+00:00</lastmod>
<priority>0.5</priority>
</url>
<url>
<loc>http://www.dotnet-friends.com/Tutorials/tut2.aspx</loc>
<lastmod>2006-06-23T21:19:54+00:00</lastmod>
<priority>0.5</priority>
</url>
<url>
<loc>http://www.dotnet-friends.com/Tutorials/CSharp/tut3.aspx</loc>
<lastmod>2006-09-18</lastmod>
</url>
</urlset>
|