网页上读取远程xml的数据

一个客户提供一个股价的信息,要求放在页面上,显示一些数据,需要从远程获取xml,然后解析写在网页上,开始不会觉得很难,其实蛮简单的,先用javascript写了一个:

1<script language="javascript">   
2var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");   
3xmlDoc.async="false";   
4xmlDoc.load(" http://****.com/scripts/****.asp?subcode=C22 ");   
5nodes = xmlDoc.documentElement.childNodes;   
6var text = xmlDoc.selectSingleNode("//last").text   
7document.write(text);   
8</script>

http://.com/scripts/.asp?subcode=C22 ,是客户提供的页面,其实是xml的内容,这里直接调用windows的组件进行读取,然后调用其中一个selectSingleNode的方法,读出last字段的内容;
VBscript也写了一个,其实差不多,不过有一点不同,asp中VB的不能直接读取远程xml的内容,很奇怪,不知道是不是由于VB的限制:

dim XMLMorntekDocument
Set http=Server.CreateObject("Microsoft.XMLHTTP")
http.Open "GET"," http://com/scripts/**.asp?subcode=C22",False
http.send
Set XMLMorntekDocument=Server.CreateObject("Microsoft.XMLDOM")
XMLMorntekDocument.Async=False
XMLMorntekDocument.ValidateOnParse=False
XMLMorntekDocument.Load(http.ResponseXML)
price = XMLMorntekDocument.selectSingleNode("//last").text
response.write price
Set http=Nothing
Set XMLMorntekDocument=Nothing

这里先用XMLHTTP的方法,get到xml文件,然后再解析。

Published At
Categories with Web编程
Tagged with
comments powered by Disqus