今天突然在网上发现自己以前的一个求助的帖子,问题已经解决了,今天就把它收到博客里来.
一个客户需要在网上读取准实时的公司股票信息,客户提供如下xml输出的地址.
现在我要从这个地址上读取信息http://esite.sgx.com/scripts/GenXML_SGXPriceMDDL.asp?subcode=z25
要获取这段代码的内容:
<previousClose>1.200</previousClose>
<open>1.200</open>
<last>1.200</last>
<bid>1.190</bid>
<offer>1.200</offer>
<high>1.200</high>
<low>1.200</low>
怎么获取?
代码如下:
- <%@ Language=VBScript %>
- <%on error resume next
- ' define the variables
- dim objHTTP
- dim objXML
- dim objLst
- ' set-up XMLHTTP
- set objHTTP = Server.CreateObject("Microsoft.XMLHTTP")
- ' get the requested XML data from the remote location
- ' change the URL as per your feed.
- objHTTP.open "GET", "http://esite.sgx.com/scripts/GenXML_SGXPriceMDDL.asp?subcode=z25", false
- objHTTP.send
- ' save the XML in objXML as XML
- set objXML = objHTTP.responseXML
- %>
- <%
- Set objLst = Server.CreateObject("Microsoft.XMLDOM")
- Set objConfig = Server.CreateObject("Microsoft.XMLDOM")
- objXML.async = False
- If objXML.parseError.errorcode <> 0 then
- ' Error parsing XML file
- Response.Write "Error parsing XML File"
- Else
- ' No error
- Set objLst = objXML.getElementsByTagName("equityDomain")
- Set objConfig = objLst.item(0).childNodes(0)
- nameFull = objConfig.childNodes(2).text
- Set objLst = objXML.getElementsByTagName("tradePrice")
- Set objConfig = objLst.item(0)
- prevClose = objConfig.childNodes(0).text
- curOpen = objConfig.childNodes(1).text
- last = objConfig.childNodes(2).text
- bid = objConfig.childNodes(3).text
- offer = objConfig.childNodes(4).text
- high = objConfig.childNodes(5).text
- low = objConfig.childNodes(6).text
- change = objConfig.childNodes(7).text
- percent = objConfig.childNodes(8).text
- Set objLst = objXML.getElementsByTagName("tradeVolume")
- Set objConfig = objLst.item(0)
- bidVol = objConfig.childNodes(0).text
- offerVol = objConfig.childNodes(1).text
- totalVol = objConfig.childNodes(2).text
- Set objLst = objXML.getElementsByTagName("header")
- Set objConfig = objLst.item(0)
- last_update_datetime = objConfig.childNodes(0).text
- neirong2 = objConfig.childNodes(1).text
- End If
- Set objXML = Nothing
- Set objLst = Nothing
- Set objConfig = Nothing
- %>
但是这段代码一直取不到值?
问题解决
最后才发现问题不出在程序上,程序写的没有任何问题,原来是调用的xml文件输出地址区分大小写:
http://esite.sgx.com/scripts/GenXML_SGXPriceMDDL.asp?subcode=z25 这个地址本身就没有数据输出
http://esite.sgx.com/scripts/GenXML_SGXPriceMDDL.asp?subcode=Z25这个地址才是对的;
修改
objHTTP.open "GET", "http://esite.sgx.com/scripts/GenXML_SGXPriceMDDL.asp?subcode=z25", false
为
objHTTP.open "GET", "http://esite.sgx.com/scripts/GenXML_SGXPriceMDDL.asp?subcode=Z25", false
后就可以正常获取数据了
URL :http://blog.youkuaiyun.com/vince6799