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

google|sitemap|xml|生成xml

ASP版本,需要空间的FSO支持
使用方法就不说了

版主觉的可以,给个精
第一次哦

  CODE: [Copy to clipboard]   
<%
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
%>

时间: 2024-10-17 13:21:56

直接生成XML的Google SiteMap代码[ASP版本]的相关文章

asp +access 生成 xml文档实例代码

<?xml version="1.0" encoding="utf-8"?> <photos>        <photo filename="大图片的路径" thumbnail="小图的路径" description="图片表述" /> </photos> <% Dim sSQL dim rs dim sCrLf dim sXmlClear dim s

Google Sitemap更快更全面收录网站

     Google新推出的sitemap,是对原来robots.txt的扩展,sitemap!使用xml格式来记录整个网站的信息并供google读取,使搜索引擎能更快更全面的收录网站的内容.     sitemap的作用就好像为网站提供了整站的rss,而google就是这些rss的订阅者,只要网站有更新就会自动通知google.这样一来,搜索引擎的收录由被动的pull变成了主动的push,辛苦的google爬虫们终于可以松一口气了.     快来尝试下:https://www.google.

asp.net递归生成XML树的示例

asp.net|xml|生成xml|示例|递归 asp.net递归生成XML树的示例 代码: 以下是引用片段://CDepartmentInfo 类别实体类 //sjid :与大类别关联ID //space:只是一个标记 //strOpinion用来存放类名 string sjid = "0"; string space = "+"; string strOpinion = ""; string paths = @"E:\test&qu

shell脚本实现快速生成xml格式sitemap实例分享_linux shell

用shell快速生成xml格式的sitemap地图文件,中小型网站适用.在本次案例中,生成12053条URL的sitemap文件,仅用时4.3秒!shell代码如下: 复制代码 代码如下: cat sitemap.txt|awk 'BEGIN{print "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<urlset>"}{print "<url>\n<

asp.net下C#生成XML文件各种方法

XmlDocument保存文件  代码如下 复制代码 XmlDocument doc = new XmlDocument();             try             {                 doc.Load("new.xml");             }             catch             {                 XmlTextWriter xtw = new XmlTextWriter("new.xml&

一行代码生成Google SiteMap

google|sitemap javascript:var%20u=document.location.href;var%20t=prompt('输入更新时间:\n\n\n','');var%20p=prompt('输入索引等级:\n\n\n','1.0');var%20c=prompt('输入更新频率:\n\n\n','Always');var%20l=document.links;var%20s='\n';for(var%20i=0;i\n'+l[i]+'\n'+t+'\n'+c+'\n'+

Python中使用dom模块生成XML文件示例_python

在Python中解析XML文件也有Dom和Sax两种方式,这里先介绍如何是使用Dom解析XML,这一篇文章是Dom生成XML文件,下一篇文章再继续介绍Dom解析XML文件. 在生成XML文件中,我们主要使用下面的方法来完成. 主要方法 1.生成XML节点(node) 复制代码 代码如下: createElement("node_name") 2.给节点添加属性值(Attribute) 复制代码 代码如下: node.setAttribute("att_name",

为google量身定做的sitemap生成代码asp版_应用技巧

外面很多所谓sitemap生成代码都只生成目录文件地址,没生成动态的,我后来自己写了这个,是支持动态的,例子: 如你是文章网站,文章有2000条,那你修改下对应你的文章数据表,即可生成除了所有目录文件外,还生成你的动态2000条地址,绝对的没话说,生成速度非常快 把下面代码保存为sitemap.asp文件,修改我已注明的几个地方,其他的一概不要修改,好不好用过才知道. 复制代码 代码如下: <!--#include file="conn.asp"--> <% sess

为google量身定做的sitemap生成代码asp版

外面很多所谓sitemap生成代码都只生成目录文件地址,没生成动态的,我后来自己写了这个,是支持动态的,例子: 如你是文章网站,文章有2000条,那你修改下对应你的文章数据表,即可生成除了所有目录文件外,还生成你的动态2000条地址,绝对的没话说,生成速度非常快 把下面代码保存为sitemap.asp文件,修改我已注明的几个地方,其他的一概不要修改,好不好用过才知道. 复制代码 代码如下: <!--#include file="conn.asp"--> <% sess