Solved

XML Foreign Exchange rate inserted into ASP (VBScript)

Posted on 2004-08-26
5
312 Views
Last Modified: 2010-08-05
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("Microsoft.XMLDOM")
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.childNodes
IF xml.selectSingleNode("RateList/Rate[" & count & "]/Country").text = "European Monetary Union" THEN
'euro = xml.documentElement.childNodes(count).text
euro = xml.selectSingleNode("RateList/Rate[" & count & "]/Value").text
END IF
IF xml.selectSingleNode("RateList/Rate[" & count & "]/Country").text = "United Kingdom" THEN
'euro = xml.documentElement.childNodes(count).text
pound = xml.selectSingleNode("RateList/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
0
Comment
Question by:mwidd101
  • 3
  • 2
5 Comments
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 11909678
0
 

Author Comment

by:mwidd101
ID: 11910931
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'
0
 

Author Comment

by:mwidd101
ID: 11911583
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("Microsoft.XMLHTTP")


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.childNodes
IF xml.selectSingleNode("RateList/Rate[" & count & "]/Country").text = "European Monetary Union" THEN
'euro = xml.documentElement.childNodes(count).text
euro = xml.selectSingleNode("RateList/Rate[" & count & "]/Value").text
END IF
IF xml.selectSingleNode("RateList/Rate[" & count & "]/Country").text = "United Kingdom" THEN
'euro = xml.documentElement.childNodes(count).text
pound = xml.selectSingleNode("RateList/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
0
 
LVL 75

Accepted Solution

by:
Anthony Perkins earned 500 total points
ID: 11913283
As I suggested previously, change:
xml.Open "GET", "http://www.ny.frb.org/markets/fxrates/FXtoXML.cfm?FEXdate=2004%2D08%2D26%2000%3A00%3A00&FEXtime=1200", false
xml.Send ""

To:
xml.Open "GET", "http://www.ny.frb.org/markets/fxrates/FXtoXML.cfm?FEXdate=2004%2D08%2D26%2000%3A00%3A00&FEXtime=1200", false
xml.Send

Unlike a POST, with a GET there is nothing to send (no payload).

0
 

Author Comment

by:mwidd101
ID: 11914227
Good point, cheers for pointing that out
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now