分类: 系统运维
2008-05-24 08:16:18
asp + 读取rss 测试成功两例
例子1:
<% @language="VBScript"%>
<%
Function readrss(xmlseed)
dim xmlDoc
dim http
Set http=Server.CreateObject("Microsoft.XMLHTTP")
http.Open "GET",xmlseed,False
http.send
Set xmlDoc=Server.CreateObject("Microsoft.XMLDOM")
xmlDoc.Async=False
xmlDoc.ValidateOnParse=False
xmlDoc.Load(http.ResponseXML)
Set item=xmlDoc.getElementsByTagName("item")
if item.Length<=10 then
%>
<%
else
For i=0 To (item.Length-1)
Set title=item.Item(i).getElementsByTagName("title")
Set link=item.Item(i).getElementsByTagName("link")
Response.Write(""& title.Item(0).Text &"
")
Next
end if
End Function
%>
<%
call readrss("")
%>
<%
call readrss("")
%>
例子2:
==============================================================================
<%
dim xmlurl
xmlurl = "" '你要读取的xml文件
dim http
dim node,i,nodecount
Set http=Server.CreateObject("MSXML2.XMLHTTP")
http.Open "GET",xmlurl,False
http.send
Set Doc=Server.CreateObject("Microsoft.XMLDOM")
Doc.Async=False
Doc.ValidateOnParse=False
Doc.Load(http.ResponseXML)
set nodeLis = Doc.getElementsByTagName("item")
%>
文章名 发表日期 分类
<%
For i=0 to nodeLis.length-1
If nodeLis(i).selectSingleNode("category") Is Nothing Then Exit For
%> 第 <%=i+1%> 条记录:
<%=nodeLis(i).selectSingleNode("title").text%>
<%=nodeLis(i).selectSingleNode("category").text%>
<%=nodeLis(i).selectSingleNode("pubDate").text%>
<%
Next
Set Doc = Nothing
%>