Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Basic Question: extracting data from an xml file

Status
Not open for further replies.

NormRumac

Programmer
Sep 4, 2003
41
0
0
CA
Forgive me as I am a total newbie when it comes to XML.

I want to obtain particular data (today's foreign exchange rate) from the following file residing in some remote webserver (see URL below):


First of all, is it possible to do this with Internet explorer?

Secondly, is there an windows based ODBC driver which will allow me to connect to this remote webserver an extract the data I want?

I apologize if the above message is confusing, so let me know where I can clarify...

Thanks in advance,
--Norm
 
Well, with IE you sure can get the data visible: if I double-click the link IE shows the file alright.
Question is: what do you want to with it?
 
I want to obtain the value of the exchange rate relative to the Canadian dollar. In other words, from the link above, I want the value (1.308) between the <value> tag listed below:

<Country UnitName="Dollar">Canada</Country>
<Value InUsd="false">1.308</Value>


I don't want to have to load up internet explorer to grab this value. I want to write my own program that uses some external driver which can extract this specific value from the file (which happens to be hosted in some remote web server).

Thanks,
--Norm
 
I see.
You could MSXML2.DomDocument to get your value.
Here's a routine in VB:
Code:
Private Function ExchangeRateCanadianDollar() As Single

Dim objDom As MSXML2.DOMDocument
Dim objNode As MSXML2.IXMLDOMNode

Set objDom = New MSXML2.DOMDocument40
objDom.async = False

If objDom.Load("[URL unfurl="true"]http://www.ny.frb.org/markets/fxrates/FXtoXML.cfm?FEXdate=2004%2D03%2D30%2000%3A00%3A00&FEXtime=1200")[/URL] Then
    Set objNode = objDom.selectSingleNode("/RateList/Rate[Country='Canada']/Value")
    If objNode Is Nothing Then
        MsgBox "Can't find Canada"
    Else
        ExchangeRateCanadianDollar = CSng(objNode.Text)
    End If
Else
    MsgBox "can't load"
End If

Set objNode = Nothing
Set objDom = Nothing

End Function
 
I overlooked that the page uses params to pass the current date.
In VB you could do:
Code:
strURL = "[URL unfurl="true"]http://www.ny.frb.org/markets/fxrates/FXtoXML.cfm?FEXdate="[/URL] & _
        Format$(Date, "yyyy") & "%2D" & _
        Format$(Date, "MM") & "%2D" & _
        Format$(Date, "dd") & _
        "%2000%3A00%3A00&FEXtime=1200" _

If objDom.Load(strURL) Then
 
Thanks for your help.

Looks like I will have to read up on this DOM stuff since I'm totally new to XML.
 
Also, one more question, if i am going to use DOM and make an XMLHTTP request, does that impose any requirements on the remote webserver? For instance, does the remote webserver need to be running ASP?
 
For instance, does the remote webserver need to be running ASP?

If it is (or isn't) wouldn't affect the format of the XML coming back -- it would only affect how you format your URL when making the request.

Chip H.


If you want to get the best response to a question, please check out FAQ222-2244 first
 
Here is a site that shows you how to do this, and lets you try it with in the site:


(Note: w3schools has info on javascript, vbscript, asp, and the rest of the web development tools)

And it's all free, and from the people who standardized all this stuff in the first place (w3c)

Good Luck, (have fun playing with the examples)

A second place to look for info is
Have Fun, Be Young... Code BASIC
-Josh
cubee101.gif


PROGRAMMER: (n) Red-eyed, mumbling mammal capable of conversing with inanimate objects.
 
Thanks for the help guys. I got it working now!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top