asp读取xml 代码
2009年9月6日星期日 | | |<%
url = "/rss.asp"
'url = "http://localhost:81/lastidea.net/rss.asp"
Set http=Server.CreateObject("Microsoft.XMLHTTP")
http.Open "GET",url,false
http.send
Set xml=Server.CreateObject("Microsoft.XMLDOM")
xml.Async=true
xml.ValidateOnParse=False
xml.Load(http.ResponseXML)
If xml.ReadyState>2 Then
''xmlhttp.readyState的4个属性
''1:LOADING;2:LOADED;3:INTERACTIVE;4:COMPLETED
''Response.Write("文档已经准备就绪。状态:"& xml.ReadyState &"<br>")
if xml.parseError.errorCode <> 0 then
response.write "错误:读取数据失败"
response.write xml.parseerror.errorcode
response.write xml.parseerror.reason
'xml.loadxml(myxmlstr)
response.End()
end if
'可一次性读出所有的值
Set itemData=xml.getElementsByTagName("item")
if isnull(xml.getElementsByTagName("item") ) then
response.Write("读取失败")
response.End()
else
for j=1 to 7
pubDate=Format_Time(xml.getElementsByTagName("pubDate").item(j).text,2)
title=xml.getElementsByTagName("title").item(j).text
link =xml.getElementsByTagName("link").item(j).text
mystr=mystr+ "<div class='underline'><img src=img/dot01.jpg> <a href="&link&" target='_blank'>"&leftStr(title,35)&"</a></div>"
next
end if
response.write mystr
'也可使用下面的方法一次只读一个值
'Set title=xml.getElementsByTagName("Uid")
'Response.Write(Format_Time(xml.getElementsByTagName("pubDate").item(0).text,2))
'Response.Write(xml.getElementsByTagName("title").item(0).text &"<br>")
'Else
'Response.Write("文档还未准备就绪。状态:"& xml.ReadyState &"<br>")
End If
Set http=Nothing
Set xml=Nothing
%>
该文章转载自[网站制作品牌服务商-南京华籁网络]:http://www.hualay.net/Article_Contents.asp?ID=94