直接生成XML的Google SiteMap的asp代码
作者:Francesco Passantino 来源:iteam5.net 发布时间:2007-08-17 13:44:00
下面提供生成XML的Google SiteMap代码[ASP版本]。
这个代码是生成全站文件链接的地图:
<%
Server.ScriptTimeout=50000
' sitemap_gen.asp
' A simple script to automatically produce sitemaps for a webserver, in the Google Sitemap Protocol (GSP)
' by Francesco Passantino
' www.iteam5.net/francesco/sitemap
' v0.2 released 5 june 2005 (Listing a directory tree recursively improvement)
'
' BSD 2.0 license,
' http://www.opensource.org/licenses/bsd-license.php
session("server")="http://www.aspxhome.com" '你的域名
vDir = "/" '制作SiteMap的目录,相对目录(相对于根目录而言)
set objfso = CreateObject("Scripting.FileSystemObject")
root = Server.MapPath(vDir)
'response.ContentType = "text/xml"
'response.write "<?xml version='1.0' encoding='UTF-8'?>"
'response.write "<urlset xmlns='http://www.google.com/schemas/sitemap/0.84'>"
str = "<?xml version='1.0' encoding='UTF-8'?>" & vbcrlf
str = str & "<urlset xmlns='http://www.google.com/schemas/sitemap/0.84'>"
& vbcrlf
Set objFolder = objFSO.GetFolder(root)
'response.write getfilelink(objFolder.Path,objFolder.dateLastModified)
Set colFiles = objFolder.Files
For Each objFile In colFiles
'response.write getfilelink(objFile.Path,objfile.dateLastModified)
str = str & getfilelink(objFile.Path,objfile.dateLastModified) & vbcrlf
Next
ShowSubFolders(objFolder)
'response.write "</urlset>"
str = str & "</urlset>" & vbcrlf
set fso = nothing
Set objStream = Server.CreateObject("ADODB.Stream")
With objStream
'.Type = adTypeText
'.Mode = adModeReadWrite
.Open
.Charset = "utf-8"
.Position = objStream.Size
.WriteText=str
.SaveToFile server.mappath("/sitemap.xml"),2 '生成的XML文件名
.Close
End With
Set objStream = Nothing
If Not Err Then
Response.Write("<script>alert('成功生成站点地图!');history.back();</script>")
Response.End
End If
Sub ShowSubFolders(objFolder)
Set colFolders = objFolder.SubFolders
For Each objSubFolder In colFolders
if folderpermission(objSubFolder.Path) then
'response.write getfilelink(objSubFolder.Path,objSubFolder.dateLastModified)
str = str & getfilelink(objSubFolder.Path,objSubFolder.dateLastModified) & vbcrlf
Set colFiles = objSubFolder.Files
For Each objFile In colFiles
'response.write getfilelink(objFile.Path,objFile.dateLastModified)
str = str & getfilelink(objFile.Path,objFile.dateLastModified) & vbcrlf
Next
ShowSubFolders(objSubFolder)
end if
Next
End Sub
Function getfilelink(file,datafile)
file=replace(file,root,"")
file=replace(file,"\","/")
If FileExtensionIsBad(file) then Exit Function
if month(datafile)<10 then filedatem="0"
if day(datafile)<10 then filedated="0"
filedate=year(datafile)&"-"&filedatem&month(datafile)&"-"&filedated&day(datafile)
getfilelink = "<url><loc>"&server.htmlencode(session("server")&vDir&file)&"</loc><lastmod>"&filedate&"</lastmod><changefreq>daily</changefreq><priority>1.0</priority></url>"
Response.Flush
End Function
Function Folderpermission(pathName)
'需要过滤的目录(不列在SiteMap里面)
PathExclusion=Array("\temp","\_vti_cnf","_vti_pvt","_vti_log","cgi-bin","\admin","\edu")
Folderpermission =True
for each PathExcluded in PathExclusion
if instr(ucase(pathName),ucase(PathExcluded))>0 then
Folderpermission = False
exit for
end if
next
End Function
Function FileExtensionIsBad(sFileName)
Dim sFileExtension, bFileExtensionIsValid, sFileExt
'modify for your file extension (http://www.googleguide.com/file_type.html)
Extensions = Array("png","gif","jpg","jpeg","zip","pdf","ps","html","htm","php","wk1","wk2","wk3","wk4","wk5","wki","wks","wku","lwp","mw","xls","ppt","doc","swf","wks","wps","wdb","wri","rtf","ans","txt")
'设置列表的文件名,扩展名不在其中的话SiteMap则不会收录该扩展名的文件
if len(trim(sFileName)) = 0 then
FileExtensionIsBad = true
Exit Function
end if
sFileExtension = right(sFileName, len(sFileName) - instrrev(sFileName, "."))
bFileExtensionIsValid = false 'assume extension is bad
for each sFileExt in extensions
if ucase(sFileExt) = ucase(sFileExtension) then
bFileExtensionIsValid = True
exit for
end if
next
FileExtensionIsBad = not bFileExtensionIsValid
End Function
%>
猜你喜欢
- 代码如下:--建立数据表createtable TestData ( ID int identity(1,1) primary key, D
- XML是一个精简的SGML,它将SGML的丰富功能与HTML的易用性结合到Web的应用中。XML保留了SGML的可扩展功能,这使XML从根本
- 好久没有写ASP代码了,今天在做一个简单的留言本时,出现了一下错误:Microsoft Office Access Database Eng
- <form name="frm"><select name=school onchange="
- 本文详细列出了HTML中使用到的各种鼠标事件,如onclick,onmouseover等;页面相关事件如:onerror,onload等;h
- 情景一: var yx01 = new function() {return "圆心"}; alert(yx01);我们
- 去年淘宝做了个“胖子”项目,就是把网页的默认宽度从780提升到了950。也就是说,基本放弃了800×600的用户(没有完全放弃,如果你仔细研
- 作者的blog :http://www.planabc.net/老甘的《完全用CSS实现的中英文双语导航菜单》一文中使用“position:
- 最近没事,写了个在项目经常要取城市或省份名的方法,所以改成了一个类.方便以后调用//****************************
- 设置MySQL数据同步(单向&双向)由于公司的业务需求,需要网通和电信的数据同步,就做了个MySQL的双向同步,记下过程,以后用得到
- CSS2.1 中规定了关于 CSS 规则 Specificity(特异性)的计算方式,用一个四位的数字串(注:CSS2 中是用三位)来表示,
- 很多朋友使用Dreamweaver一段时间后,开始热衷于寻找各式各样的插件,追求各种各样的特效,而对于Dreamweaver中的基本功能反而
- 在seclists中看到一个很惊人的thread:http://seclists.org/oss-sec/2012/q2/493MySQL爆
- 对大家推荐很好使用的MySql节点系统,像让大家对MySql节点系统有所了解,然后对MySql节点系统全面讲解介绍,希望对大家有用在向大家详
- 因为神奇的中文有时也是会遇到国外同学都不知道原因导致一些神奇滴问题,所以要用更神奇的英文来解决问题。Mac OS的一些:华文细黑:STHei
- 1.查询表名: 代码如下:select table_name,tablespace_name,temporary from user_tab
- 在写ASP网页时常用的检测代码:服务器现在时间:<% =now %>服务器CPU型号:<%=Request.ServerV
- 很多人错误地认为ASP是简单、低效的代名词,认为ASP是低能的,不足挂齿的,也很简单,一学就会,一琢磨就精通。有人讲ASP不安全,写ASP的
- 经常到这来抄抄改改代码,也贡献一个代码,主要是讨论研究用,没有封装可以进一步改进<!DOCTYPE html PUBLIC "
- 一个小代码 类似资源管理器效果 支持鼠标拖拽 没写些细节东西 JavaScript语言: