[英]reading XML into classic asp
我是编程新手,还是XML新手,我知道这无济于事。
我需要读取一个看起来像这样的外部XML文件
<?xml version="1.0" encoding="UTF-8"?>
<gesmes:Envelope xmlns:gesmes="http://www.gesmes.org/xml/2002-08-01" xmlns="http://www.ecb.int /vocabulary/2002-08-01/eurofxref">
<gesmes:subject>Reference rates</gesmes:subject>
<gesmes:Sender>
<gesmes:name>European Central Bank</gesmes:name>
</gesmes:Sender>
<Cube>
<Cube time='2014-06-17'>
<Cube currency='USD' rate='1.3568'/>
<Cube currency='JPY' rate='138.40'/>
<Cube currency='BGN' rate='1.9558'/>
<Cube currency='CZK' rate='27.445'/>
在ASP页面中,我想读取并显示两种货币及其值,但是我没有找到任何看起来像这样的示例。
在此先感谢,耶隆
--
Set oXML = Server.CreateObject("MSXML2.DomDocument.4.0")
oXML.LoadXML(sXML) ' sXML is a variable containing the content of your XML file
For Each oNode In oXML.SelectNodes("/Cube/cube")
sCurrency= oNode.GetAttribute("currency")
sRate= oNode.GetAttribute("rate")
Do something with these values here
Next
Set oXML = Nothing
我使用以下代码
Sub DisplayRates
URL = "http://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml"
'URL = "localhost/wallboard/ratesxml.xml"
Set oXML = Server.CreateObject("MSXML2.DomDocument.4.0")
oXML.setProperty "ServerHTTPRequest" , True
oXML.async = False
oXML.LoadXML URL
For Each oNode In oXML.SelectNodes("/Cube/cube")
sCurrency = oNode.GetAttribute("currency")
sRate = oNode.GetAttribute("rate")
' set itemList = oXML.SelectNodes ("/Cube/cube")
'For Each itemAttrib In itemList
'sCurrency = itemAttrib.SelectSingleNode ("currency").text
'sRate = itemAttrib.SelectSingleNode ("rate").text
Response.Write "<TD ALIGN='CENTER' BGCOLOR='" & TableColor_CSQStats & "'><FONT SIZE =' " & TextSize_CSQStats & " ' COLOR='" & TextColor & "'>" & sCurrency & "</FONT></TD>"
Response.Write "<TD ALIGN='CENTER' BGCOLOR='" & TableColor_CSQStats & "'><FONT SIZE =' " & TextSize_CSQStats & " ' COLOR='" & TextColor & "'>"& sRate & "</FONT></TD>"
Next
Set oXML = Nothing
End Sub
字段未填充,使用本地文件或远程文件也没有区别。 该页面本身不会给出任何错误,并且可以正常加载。
感谢您关注它:-) Jeroen
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.