用xmldom方法打開xml文件,如果是本地的沒有問題,就是用Server.MapPath("xml.xml")的方法,這時能正常分析出內(nèi)容,但是直接用url卻不顯示出xml內(nèi)容(在XMLDOM里表示是支持URL方式的),后來研究一下發(fā)現(xiàn)可以用XMLHTTP的方法獲取XML后再分析,代碼如下: Set http=Server.CreateObject("Microsoft.XMLHTTP") http.Open "GET","http://www.knowsky.com/xml.xml",False http.send Set xml=Server.CreateObject("Microsoft.XMLDOM") xml.Async=False xml.ValidateOnParse=False xml.Load(http.ResponseXML) If xml.ReadyState>2 Then Response.Write("文檔已經(jīng)準(zhǔn)備就緒。狀態(tài):"& xml.ReadyState &"<br>") Set item=xml.getElementsByTagName("item") For i=0 To (item.Length-1) Set title=item.Item(i).getElementsByTagName("title") Set link=item.Item(i).getElementsByTagName("link") Response.Write("<a href="""& link.Item(0).Text &""">"& title.Item(0).Text &"</a><br>") Next Else Response.Write("文檔還未準(zhǔn)備就緒。狀態(tài):"& xml.ReadyState &"<br>") End If Set http=Nothing Set xml=Nothing xml.xml文檔的內(nèi)容如下:
<?xml version="1.0" encoding="utf-8"?> <channel> <item> <title>測試文檔1</title> <link>http://localhost/</link> </item> <item> <title>測試文檔2</title> <link>http://localhostindex.asp</link> </item> </channel>
|