German Wear Discount Shop - Click Here Write for Dotnet-friends and earn for your each submission [Dot]Net-Friends
Skip Navigation Links
Home
Latest
Fast Code
Articles
Tutorials
Online Resources
Forums
Login   | Hi, Guest


Inserting a new Node to the Google SiteMap Dynamically

Written by omerkamal on Dec 29, 2006
How to insert a new node in to existing Google Map XML file

Introducation:

Google have its own way to access and crawl in a website. They also offered a Google sitemap. This make easy for webmasters to tell Searcher their priorities. This way they can communicate with the searchee that what is importent for them and what pages are edit preriodically.

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

Visitors/Readers Comments
(for questions please use The Forum)



Norman

This Google Node Update Script is Good! Excellent work & thanks!

My site is based on ASP.NET vb. Is that possible to chage this funtion to vb scripting?

Cheers, Norman

 

18/04/2008 09:17:06 UTC

kamal

Here is the VB .NET version of the function:

Protected Sub WriteGoogleMapEntry(ByVal PagePath As String)

    Dim doc As New XmlDocument()

    Dim path As String = Server.MapPath("~/map.xml")

    doc.Load(path)   

    Dim docFrag As XmlDocumentFragment = 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"))

End Sub

19/04/2008 04:32:28 UTC




Add your Comments

Name:  
Message:
Note: For faster response please use Forums >> for your questions instead of the comments area! (Admin)