呼叫網易新聞的XML資料為例進行解說如果透過ASP遠端調取XML文件,並讀出資料。其實我們之前就已經使用了asp讀取alexa官方的資料。複製代碼代碼如下:
<%
URL=http://news.163.com/special/00011K6L/rss_newstop.xml
Set xml = Server.CreateObject(Microsoft.XMLHTTP)
xml.Open GET, url, False
xml.Send
Set xmlDom = server.createObject(microsoft.xmldom)
xmlDom.async=False
xmlDom.ValidateOnParse=false
xmlDom.load(xml.responseXML)
if xmlDom.ReadyState>2 Then
set oItem=xmlDom.getElementsByTagName(item)
%>
<table width=550 border=0 cellpadding=3 cellspacing=1 bgcolor=#ECEFF4>
<%
for i=0 to oItem.length-1
word=oItem(i).childNodes(0).text
title=oItem(i).childNodes.item(0).text
Link=oItem(i).childNodes.item(1).text
pubDate=oItem(i).childNodes.item(3).text
%>
<tr>
<td height=24 bgcolor=#FFFFFF>·<a href=<%=link%> target=_blank><font style=font-size:14px; color=#003366><%=word%> </font> <font color=#999999>(<%=pubdate%>)</font></a></td>
</tr>
<%
next
end if
%>
</table>
遠端文件的內容如下:
複製代碼代碼如下:
<?xml version=1.0 encoding=GBK?>
<?xml-stylesheet type=text/css href=http://news.163.com/css/allrss.css?>
<rss version=2.0>
<channel>
<title>網易頭條</title>
<link>http://news.163.com/</link>
<description>網易頭條</description>
<pubDate>Wed, 16 Feb 2011 02:59:02 GMT</pubDate>
<lastBuildDate>Wed, 16 Feb 2011 02:59:02 GMT</lastBuildDate>
<item id=1>
<title><![CDATA[第一線城市房租連漲]]></title>
<link>http://news.163.com/11/0216/10/6T0NIHOA00014JB6.html</link>
<description><! [CDATA[從去年底開始掀起的租金漲價潮,在春節後繼續放大。記者在春節後接連接到租金上漲的消息,北京、上海、廣州等一線城市房屋的租金持續上漲,很多中介開年後,重新刷新了年前房屋的出租價格,住房、商舖、辦公室的租金都上漲了10%左右不等。記者昨天走訪了廣州的多家中介,中介普遍反映租賃市場火熱,成交單中租單已是賣單五]]>......</description>
<pubDate>2011-02-16 10:59:02</pubDate>
</item>
<item id=2>
<title><![CDATA[山東部分麵粉廠因農民惜售商人囤糧停產]]></title>
<link>http://focus.news.163.com/11/0216/11/6T0R9MIE00011SM9.html</link>
<description><! [CDATA[民以食為天,糧價乃百價之基。 2010年下半年開始的糧價上漲引發中國經濟的連鎖反應,又因去秋以來的北方大旱加劇糧價上漲預期,最近國際糧價屢創新高。 穩定物價坐上了今年中國經濟的頭把交椅。春節期間,國務院總理溫家寶專程奔赴糧食主產區作出最新指示,國務院常務會議則迅速出台保護糧食生產的國十條。 那麼百]]>......</description>
<pubDate>2011-02-16 11:30:40</pubDate>
</item>
</channel>
</rss>