asp自动生成google/百度网站地图的xml源代码实现方法 - it之王 - 五略商书

asp自动生成google/百度网站地图的xml源代码实现方法

it之王头像

阅读 28939 | 分类:文章

Response.Buffer = True
With Response
 .Expires = -1
 .AddHeader "Pragma","no-cache"
 .AddHeader "cache-ctrol","no-cache"
End With
%>
< %
Server.ScriptTimeout=50000

Dim str,objStream
str = "<?xml version=’1.0’ encoding=’UTF-8’?>" & vbcrlf
str = str & "<urlset xmlns=’http://www.google.com/schemas/sitemap/0.84’>" & vbcrlf
str = str & getfilelink & vbcrlf
str = str & "</urlset>" & vbcrlf

Set objStream = Server.CreateObject("ADODB.Stream")
With objStream
.Open
.Charset = "UTF-8"
.Position = objStream.Size
.WriteText=str
.SaveToFile server.mappath("sitemap.xml"),2
.Close
End With
Set objStream = Nothing

If Not Err Then
   Response.Redirect("sitemap.xml")
   Response.End
End If

Function getfilelink()
   SQL="SELECT * FROM 表名 ORDER BY id DESC"
   Dim RS
   Set RS=Server.CreateObject("ADODB.RecordSet")
   RS.Open SQL,Conn,1,1

   IF RS.EOF AND RS.BOF Then
      Response.Write("<url></url>")
   Else
      Do While NOT RS.EOF
   Y=year(RS("intime"))
   if len(month(RS("intime")))=1 then
   M=0&month(RS("intime"))
   else
   M=month(RS("intime"))
   end if
   if len(day(RS("intime")))=1 then
   D=0&day(RS("intime"))
   else
   D=day(RS("intime"))
   end if
          getfilelink = getfilelink & "<url><loc>http://www.mycodes.net/html/"&RS("Classid")&"/"&RS("ID")&".Html</loc><lastmod>"&Y&"-"&M&"-"&D&"</lastmod><changefreq>"&RS("Title")&"</changefreq><priority>1.0</priority></url>"
          RS.MoveNext
      Loop
   End IF
RS.Close
Set RS=Nothing
Conn.Close
Set Conn=Nothing
End Function

留言区(共0条)

暂无留言,快来抢占沙发~
作者声明:非原创
平台声明:文章及评论仅代表作者本人观点,五略商书系信息发布平台,仅提供信息存储空间服务,如有侵权,请联系13521509118。转载请注明作者和出处:转自五略商书m.shangdiguo.com,作者it之王!