0

I am new to programming and new to XML, I know that does not help.....

I need to read an external XML file that looks like this

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

In the ASP page, I would like to read and display two currencies and their values, but I have not found any example that looks like this..

thanks in advance, Jeroen

  • Just based on your knowledge of programming, are you definitely using Classic ASP and not ASP.NET? – Paul Jun 18 '14 at 10:07

2 Answers2

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
Community
  • 1
  • 1
pee2pee
  • 3,619
  • 7
  • 52
  • 133
  • Thanks, I did read all of these articles but it did not help. I added the code above, I get no error but no data either, also tried from downloading the file to locel disk instead of weburl. – user3751836 Jun 18 '14 at 11:45
1

I use the following code

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

the fields are not filled, and it makes no difference using the local file or the remote file. the page itself does not gives any errors, and loads normally.

thanks for looking into it :-) Jeroen