当前位置: 首页 > 图文教程 > 网络编程 > ASP > 用ASP和Microsoft.XMLDOM分析远程XML文件

ASP
ASP编程中15个非常有用的例子 (二)
ASP与JSP的比较(一)
ASP与JSP的比较(二)
ASP中五种连接数据库的方法
从ASP调用SQL中的图像
用排序串字段实现树状结构(例程:连接字串)
用排序串字段实现树状结构(例程:删除贴子)
用排序串字段实现树状结构(例程:回复表单)
用排序串字段实现树状结构(例程:显示贴子内容)
用排序串字段实现树状结构(例程:显示树)
用排序串字段实现树状结构(存储过程)
用排序串字段实现树状结构(库结构)
用排序串字段实现树状结构(原理)
remote script文档(转载自微软)(一)
remote script文档(转载自微软)(二)
remote script文档(转载自微软)(三)
remote script文档(转载自微软)(四)
remote script文档(转载自微软)(五)
remote script文档(转载自微软)(六)
remote script文档(转载自微软)(七)

用ASP和Microsoft.XMLDOM分析远程XML文件


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-03   浏览: 183 ::
收藏到网摘: n/a

 

    用xmldom方法打开xml文件,如果是本地的没有问题,就是用Server.MapPath("xml.xml")的方法,这时能正常分析出内容,但是直接用url却不显示出xml内容(在XMLDOM里表示是支持URL方式的),后来研究一下发现可以用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("文档已经准备就绪。状态:"& 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("文档还未准备就绪。状态:"& xml.ReadyState &"<br>")
End If
Set http=Nothing
Set xml=Nothing


xml.xml文档的内容如下:

<?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>