Re: Google SiteMap



Here's a handler that should get you going.

Ken
Microsoft MVP [ASP.NET]

<%@ WebHandler Language="VB" Class="googlesitemap" %>
' googlesitemap.ashx
' Adapted from a C# version in
' ASP.NET 2.0 Unleashed
' http://www.superexpert.com/Books/AspNet2Unleashed/Default.aspx
' by Ken Cox [MVP - ASP.NET]
Imports System.Web
Imports System.Xml
Imports System.Text
Imports System.IO

Public Class googlesitemap : Implements IHttpHandler
Private xmlwtr As XmlWriter
Public Sub ProcessRequest _
(ByVal context As HttpContext) _
Implements IHttpHandler.ProcessRequest
context.Response.ContentType = "text/xml"
Dim settings As XmlWriterSettings = _
New XmlWriterSettings()
settings.Encoding = Encoding.UTF8
settings.Indent = True
xmlwtr = XmlWriter.Create _
(context.Response.OutputStream, settings)
xmlwtr.WriteStartDocument()
xmlwtr.WriteStartElement _
("urlset", "http://www.google.com/schemas/sitemap/0.84";)
' Add root node
AddUrl(SiteMap.RootNode)
' Add all other nodes
Dim nodes As SiteMapNodeCollection = _
SiteMap.RootNode.GetAllNodes()
For Each node As SiteMapNode In nodes
AddUrl(node)
Next node

xmlwtr.WriteEndElement()
xmlwtr.WriteEndDocument()
xmlwtr.Flush()
End Sub

Private Sub AddUrl(ByVal node As SiteMapNode)
' Skip empty Urls
If String.IsNullOrEmpty(node.Url) Then
Return
End If
' Skip remote nodes
If node.Url.StartsWith("http", True, Nothing) Then
Return
End If
' Open url tag
xmlwtr.WriteStartElement("url")
' Write location
xmlwtr.WriteStartElement("loc")
xmlwtr.WriteString(GetFullUrl(node.Url))
xmlwtr.WriteEndElement()
' Write last modified
xmlwtr.WriteStartElement("lastmod")
xmlwtr.WriteString(GetLastModified(node.Url))
xmlwtr.WriteEndElement()
' Write changefreq
xmlwtr.WriteStartElement("changefreq")
xmlwtr.WriteString("daily")
xmlwtr.WriteEndElement()
' Write priority
xmlwtr.WriteStartElement("priority")
xmlwtr.WriteString("0.8")
xmlwtr.WriteEndElement()
' Close url tag
xmlwtr.WriteEndElement()
End Sub

Private Function GetFullUrl _
(ByVal url As String) As String
Dim context As HttpContext = HttpContext.Current
Dim server As String = _
context.Request.Url.GetComponents _
(UriComponents.SchemeAndServer, UriFormat.UriEscaped)
Return Combine(server, url)
End Function

Private Function Combine _
(ByVal baseUrl As String, _
ByVal url As String) As String
baseUrl = baseUrl.TrimEnd(New Char() {"/"c})
url = url.TrimStart(New Char() {"/"c})
Return baseUrl & "/" & url
End Function

Private Function GetLastModified _
(ByVal url As String) As String
Dim context As HttpContext = HttpContext.Current
Dim physicalPath As String = _
context.Server.MapPath(url)
Return File.GetLastWriteTimeUtc _
(physicalPath).ToString("s")
End Function

Public ReadOnly Property IsReusable() _
As Boolean Implements IHttpHandler.IsReusable
Get
Return True
End Get
End Property

End Class

"shapper" <mdmoura@xxxxxxxxx> wrote in message
news:1160309405.272792.273500@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Hello,

I am trying to convert an Asp.Net 2.0 XML sitemap file to a Google's
sitemap file.

I am posting the formats of both files.

1. How can I do the conversion?

2. And can I use an .ashx Asp.Net file that when the .ashx file is
called the Google XML file is generated?

Thank You,
Miguel

GOOGLE SiteMap

<?xml version="1.0" encoding="UTF-8"?>
< urlset xmlns="http://www.google.com/schemas/sitemap/0.84";>
< url>
< loc>http://www.mydomain.com/example.aspx</loc>
< lastmod>2005-01-01</lastmod>
< changefreq>daily</changefreq>
< priority>0.8</priority>
</url>
</urlset>

ASP.NET 2.0 Site Map

<?xml version="1.0" encoding="utf-8" ?>
<siteMap
xmlns = "http://schemas.microsoft.com/AspNet/SiteMap-File-1.0"; >
<siteMapNode>
<siteMapNode
url = "~/example.aspx"
changefreq = "daily"
lastmod = "2005-01-01"
description = "My example page and its contents"
priority = "0.8"
title = "Example page" />
</siteMapNode>
</siteMap>

Note: description and title should be droped when converting from
Asp.Net to Google sitemap.



.



Relevant Pages

  • Sitemap trimming with Forms auth (Active Directory)
    ... just to try get the sitemap working properly so I'm not worried about ... "FormsIdentity") Then ... Dim ticket As FormsAuthenticationTicket = ... Dim userData As String = ticket.UserData ...
    (microsoft.public.dotnet.framework.aspnet.security)
  • SiteMapResolve Event does not fire
    ... I have a simple wesite with a SiteMap. ... Some of the URLs in the site map refer to external pages ... Dim currentNode As SiteMapNode = SiteMap.CurrentNode.Clone ... 'Dim x As String = currentNode.Title ...
    (microsoft.public.dotnet.framework.aspnet)
  • Search pattern
    ... Dim strfile As String ... Dim bAddressFound As Boolean ... Dim strCurrentChar As String ...
    (comp.databases.ms-access)
  • Re: multiplatform (pocketPC & desktopPC) (Daniel !!)
    ... Friend Versione As String ... Public Sub GetMyConnectionPalmare() ... Dim errorMessages As String ... Private Function GetDS_Desktop(ByVal SQL As String) As DataSet ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: multiplatform (pocketPC & desktopPC) (Daniel !!)
    ... Friend Versione As String ... Public Sub GetMyConnectionPalmare() ... Dim errorMessages As String ... Private Function GetDS_Desktop(ByVal SQL As String) As DataSet ...
    (microsoft.public.dotnet.framework.compactframework)