伊缘网 首页
 设为首页    加入收藏    用户帮助    联系我们 
网站首页 新闻动态 技术文章 Flash整站 精彩网文 资源下载 视频教程
网上商城 Flash动漫 网页特效 酷站欣赏 BBS论坛 在线工具 留言本站
  F-CMS Flash CMS   CXT Flash Cms   SXW Flash CMS   EXW Flash Cms   
  您的位置: 伊缘网 >> 网络学堂 >> 建站技术 >> ASP 编程
 阅读文章

直接生成XML的Google SiteMap代码[ASP版本]

  文章作者:佚名来源:转摘浏览次数:3706字体:
 阅读权限:游客身份阅读花费:0 E币添加时间:2006-11-29 下午 11:44:33提交会员:esing
皮具制造生产企业,专注时尚包包
提示:登陆本站会员系统后,网站系统将不显示任何广告!如果您还不是本站会员请注册本站会员,谢谢您对本站的关注!
  

根据森林提供的代码修改完成
在GG已经通过

ASP版本,需要空间的FSO支持

<%
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
'' 收集整理:        重庆森林@im286.com


session("server")="http://192.168.0.111"                ''你的域名
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
%>


  Tags:  ASP  
·上篇文章:将Access数据转换为XML格式
·下篇文章:轮换广告代码
复制 】 【 打印
 相关文章
·百度资料: 直接生成XML的Google SiteMap代码[ASP版本]
·asp.net 上传图片+自动生成缩略图+图片水印功能 2010-6-13 下午 05:28:41
·动手写个小组件(组件入门)_ASP 2010-5-23 上午 09:02:24
·ASP无组件上传错误 "80004005"解决方法 2010-4-26 下午 03:48:08
·ASP生成UTF-8文件实例 2010-1-8 上午 12:26:34
·在IE8下无组件上传错误"800a0005"的解决方法 2009-6-25 下午 06:27:51
特别声明:本站除部分特别声明禁止转载的专稿外的其他文章可以自由转载,但请务必注明出处和原始作者。文章版权归文章原始作者所有。对于被本站转载文章的个人和网站,我们表示深深的谢意。如果本站转载的文章有版权问题请联系我们,我们尽快予以更正,谢谢。
 相关评论
【文章评论已关闭】
伊缘网