Reputation: 11
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
Upvotes: 0
Views: 2045
Reputation: 11
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
Upvotes: 1
Reputation: 3802
-
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
Upvotes: 1