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;
https://dotnet-friends.com
2006-06-23T21:19:54+00:00
0.6
https://dotnet-friends.com/Tutorials/tut1.aspx
2006-06-23T21:19:54+00:00
0.5
https://dotnet-friends.com/Tutorials/tut2.aspx
2006-06-23T21:19:54+00:00
0.5
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 = "https://dotnet-friends.com/" +
PagePath + "" + DateTime.Now.ToString("yyyy-MM-dd") + "";
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;
https://dotnet-friends.com
2006-06-23T21:19:54+00:00
0.6
https://dotnet-friends.com/Tutorials/tut1.aspx
2006-06-23T21:19:54+00:00
0.5
https://dotnet-friends.com/Tutorials/tut2.aspx
2006-06-23T21:19:54+00:00
0.5
https://dotnet-friends.com/Tutorials/CSharp/tut3.aspx
2006-09-18
|