【问题标题】:reading XML into classic asp将 XML 读入经典 asp
【发布时间】:2014-06-19 16:38:13
【问题描述】:

我是编程新手和 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 页面中,我想读取并显示两种货币及其值,但我没有找到任何看起来像这样的示例..

提前致谢, 杰伦

【问题讨论】:

  • 仅根据您的编程知识,您确定使用的是 Classic ASP 而不是 ASP.NET?

标签: xml asp-classic


【解决方案1】:

-

    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

【讨论】:

  • 谢谢,我确实阅读了所有这些文章,但没有帮助。我添加了上面的代码,我没有收到错误但也没有数据,还尝试将文件下载到 locel 磁盘而不是 weburl。
【解决方案2】:

我使用下面的代码

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

字段不填,使用本地文件或远程文件没有区别。页面本身没有报错,正常加载。

感谢您的调查 :-) 杰伦

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多