mwidd101
asked on
XML Foreign Exchange rate inserted into ASP (VBScript)
Hi,
I'm having trouble getting to 2 values from a xml file which are located on a another server. If I place the file locally I can get it to work fine. Heres the code for it to work locally can someone please let me know how to retrieve the xml from http://www.ny.frb.org/markets/fxrates/FXtoXML.cfm?FEXdate=2004%2D08%2D25%2000%3A00%3A00&FEXtime=1200 so I can place it into the variables I want.
<%
Option Explicit
Response.Buffer = True
Dim xml
Set xml = Server.CreateObject("Micro soft.XMLDO M")
xml.async = false
xml.load (Server.MapPath("exchange. xml"))
dim euro, pound, exchange_rate
dim count, item
count = 0
for each item in xml.documentElement.childN odes
IF xml.selectSingleNode("Rate List/Rate[ " & count & "]/Country").text = "European Monetary Union" THEN
'euro = xml.documentElement.childN odes(count ).text
euro = xml.selectSingleNode("Rate List/Rate[ " & count & "]/Value").text
END IF
IF xml.selectSingleNode("Rate List/Rate[ " & count & "]/Country").text = "United Kingdom" THEN
'euro = xml.documentElement.childN odes(count ).text
pound = xml.selectSingleNode("Rate List/Rate[ " & count & "]/Value").text
END IF
count = count + 1
next
exchange_rate = pound / euro
%>
<!doctype html public "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Show me Some XML</title>
</head>
<body>
<%
response.write (euro & "<br>")
response.write (pound & "<br>")
response.write ("The exchange rate is " & exchange_rate & "<br>")
%>
</body>
</html>
I've tried using:
xml.Open "POST", "http://www.ny.frb.org/markets/fxrates/FXtoXML.cfm?FEXdate=2004%2D08%2D25%2000%3A00%3A00&FEXtime=1200", false
xml.Send ""
But I just can't get it to work.
Thanks
I'm having trouble getting to 2 values from a xml file which are located on a another server. If I place the file locally I can get it to work fine. Heres the code for it to work locally can someone please let me know how to retrieve the xml from http://www.ny.frb.org/markets/fxrates/FXtoXML.cfm?FEXdate=2004%2D08%2D25%2000%3A00%3A00&FEXtime=1200 so I can place it into the variables I want.
<%
Option Explicit
Response.Buffer = True
Dim xml
Set xml = Server.CreateObject("Micro
xml.async = false
xml.load (Server.MapPath("exchange.
dim euro, pound, exchange_rate
dim count, item
count = 0
for each item in xml.documentElement.childN
IF xml.selectSingleNode("Rate
'euro = xml.documentElement.childN
euro = xml.selectSingleNode("Rate
END IF
IF xml.selectSingleNode("Rate
'euro = xml.documentElement.childN
pound = xml.selectSingleNode("Rate
END IF
count = count + 1
next
exchange_rate = pound / euro
%>
<!doctype html public "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Show me Some XML</title>
</head>
<body>
<%
response.write (euro & "<br>")
response.write (pound & "<br>")
response.write ("The exchange rate is " & exchange_rate & "<br>")
%>
</body>
</html>
I've tried using:
xml.Open "POST", "http://www.ny.frb.org/markets/fxrates/FXtoXML.cfm?FEXdate=2004%2D08%2D25%2000%3A00%3A00&FEXtime=1200", false
xml.Send ""
But I just can't get it to work.
Thanks
ASKER
I've changed it to
xml.Open "POST", "http://www.ny.frb.org/markets/fxrates/FXtoXML.cfm?FEXdate=2004%2D08%2D25%2000%3A00%3A00&FEXtime=1200", false
xml.Send ""
but got this error message:
Microsoft VBScript runtime (0x800A01B6)
Object doesn't support this property or method: 'Open'
xml.Open "POST", "http://www.ny.frb.org/markets/fxrates/FXtoXML.cfm?FEXdate=2004%2D08%2D25%2000%3A00%3A00&FEXtime=1200", false
xml.Send ""
but got this error message:
Microsoft VBScript runtime (0x800A01B6)
Object doesn't support this property or method: 'Open'
ASKER
Hi,
Thanks for the help acperkins but I've got it working now, I needed to have: Set xml = xml.ResponseXml
Here's the working code:
<%
Option Explicit
Response.Buffer = True
Dim xml
Set xml = Server.CreateObject("Micro soft.XMLHT TP")
xml.Open "GET", "http://www.ny.frb.org/markets/fxrates/FXtoXML.cfm?FEXdate=2004%2D08%2D26%2000%3A00%3A00&FEXtime=1200", false
xml.Send ""
Set xml = xml.ResponseXml
dim euro, pound, exchange_rate
dim count, item
count = 0
for each item in xml.documentElement.childN odes
IF xml.selectSingleNode("Rate List/Rate[ " & count & "]/Country").text = "European Monetary Union" THEN
'euro = xml.documentElement.childN odes(count ).text
euro = xml.selectSingleNode("Rate List/Rate[ " & count & "]/Value").text
END IF
IF xml.selectSingleNode("Rate List/Rate[ " & count & "]/Country").text = "United Kingdom" THEN
'euro = xml.documentElement.childN odes(count ).text
pound = xml.selectSingleNode("Rate List/Rate[ " & count & "]/Value").text
END IF
count = count + 1
next
exchange_rate = pound / euro
%>
<!doctype html public "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Show me Some XML</title>
</head>
<body>
<%
response.write (euro & "<br>")
response.write (pound & "<br>")
response.write ("The exchange rate is " & exchange_rate & "<br>")
%>
</body>
</html>
Cheers
Thanks for the help acperkins but I've got it working now, I needed to have: Set xml = xml.ResponseXml
Here's the working code:
<%
Option Explicit
Response.Buffer = True
Dim xml
Set xml = Server.CreateObject("Micro
xml.Open "GET", "http://www.ny.frb.org/markets/fxrates/FXtoXML.cfm?FEXdate=2004%2D08%2D26%2000%3A00%3A00&FEXtime=1200", false
xml.Send ""
Set xml = xml.ResponseXml
dim euro, pound, exchange_rate
dim count, item
count = 0
for each item in xml.documentElement.childN
IF xml.selectSingleNode("Rate
'euro = xml.documentElement.childN
euro = xml.selectSingleNode("Rate
END IF
IF xml.selectSingleNode("Rate
'euro = xml.documentElement.childN
pound = xml.selectSingleNode("Rate
END IF
count = count + 1
next
exchange_rate = pound / euro
%>
<!doctype html public "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Show me Some XML</title>
</head>
<body>
<%
response.write (euro & "<br>")
response.write (pound & "<br>")
response.write ("The exchange rate is " & exchange_rate & "<br>")
%>
</body>
</html>
Cheers
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Good point, cheers for pointing that out
xml.Open "POST", "http://www.ny.frb.org/markets/fxrates/FXtoXML.cfm?FEXdate=2004%2D08%2D25%2000%3A00%3A00&FEXtime=1200", false
xml.Send ""
To:
xml.Open "GET", "http://www.ny.frb.org/markets/fxrates/FXtoXML.cfm?FEXdate=2004%2D08%2D25%2000%3A00%3A00&FEXtime=1200", false
xml.Send