Welcome! Log In Create A New Profile

Advanced

Try web service on exchange rates - windev

Posted by PETER ZHOU 
PETER ZHOU
Try web service on exchange rates - windev
October 13, 2008 04:59AM
Hi

Anybody tried web service/feeds on exhange rates on windev ?

Any sample code that you can share ?

Regards,

PETER ZHOU
DarrenF
Re: Try web service on exchange rates - windev
November 11, 2008 01:24PM
Hi Peter,

Did you get any further with this?

It's something I'll be looking into as part of my current project.

I've just found a site that offers a free XML data feed for a selected currency - for example:

[www.currencysource.com]

I suppose with WD's XML functions it shouldn't be too difficult to download and parse the XML file?
PETER ZHOU
Re: Try web service on exchange rates - windev
November 13, 2008 03:57PM
Quote
DarrenF
Hi Peter,

Did you get any further with this?

It's something I'll be looking into as part of my current project.

I've just found a site that offers a free XML data feed for a selected currency - for example:

[www.currencysource.com]

I suppose with WD's XML functions it shouldn't be too difficult to download and parse the XML file?

___________________________________________
Regards,
Darren Farmer.

Hi Darren,

No...I've to do something else so didn't have the time to explore further.

How about you?

Regards,

PETER ZHOU
DarrenF
Re: Try web service on exchange rates - windev
November 13, 2008 04:41PM
Hi Peter,

Yes - take a look at the post I made today regarding RSS data feeds etc...

Fabrice has posted a reply on how to download the XML file from a HTTP sourced file.

That was the gap in my knowledge.

Cheers...
Geert Debruyne
Re: Try web service on exchange rates - windev
November 13, 2008 04:44PM
Hi,
we use Webservices very often... most of the services have to be paid for, especially if it is about something professional (eg ViaMichelin to find destinations or calculate distances).
But Windev supports tehm very well, there is native support voor XML so mostly it does not take a lot of time to get things working for you.
Beware: some functions can be tricky to use because parameter-values are not 'typed' te same way as we know from Windev (integer, real....)

DarrenF
Re: Try web service on exchange rates - windev
November 14, 2008 12:17PM
Hi Geert,

Yes, after looking around, most of the data feeds must be paid for - that's why I was surprised to find this one for free. Only problem is, I suppose you can't rely on it's reliability or on it being there forever when it's free! But for now it's there and free, so I'll use it winking smiley

With Fabrice's help I've managed to link to the feed, auto download it and start to parse the XML using the XML functions :spos:

Once I've written the code to update my currency table with the rates I'll post my code on the forum (probably on the solutions forum) :-)

Cheers...
Bob Stratton (bosher)
Re: Try web service on exchange rates - windev
November 16, 2008 03:33PM
Well, It's not very scientific but using httpgetrequest pointed at google with a search string like 'gbp to usd'.

You can parse the result and get the value.

A bit crap, but it works great

Cheers

Bob
DarrenF
Re: Try web service on exchange rates - windev
November 17, 2008 02:28AM
Hi Bob,

Thanks for your thoughts...

Sounds good, but I suppose you'll need to parse for each currency you need?

The url above returns 30 or so currencies relative to the base currency you send, so if you send GBP.xml you get all the currencies relative to Sterling, but if you specify USD.xml you get all relative to US dollars etc...

It's quite a neat solution... for as long as it last that is ;-)

Cheers...
Glenn Rathke
Re: Try web service on exchange rates - windev
November 19, 2008 06:40PM
Hi Darren,

I'd be interested in seeing the code for sending the request and processing the returned xml results.

Thanks
Glenn Rathke
DarrenF
Re: Try web service on exchange rates - windev
November 19, 2008 08:05PM
Hi,

Your wish is my command Glenn winking smiley

Although not the most robust code I've ever written, it suits my purposes (...so go easy on me guys) - here's the code (mostly comments) :spos:

glocalbReqResult is boolean
glocalsTempstring is string
glocalsTempcurrency is string
glocalsTemprate is string
glocaliTempcount is int
glocalcTempChar is character

// Initiate the HTTP request
glocalbReqResult = HTTPRequest("[www.currencysource.com]winking smiley

// Are we ok to continue?
IF glocalbReqResult = True THEN
	
	// Move the resulting XML to the edit control for review on the window
	WEDIT_XML_View = HTTPGetResult()
	
	// Create a document based on this XML before we can begin
	XMLDocument("ExRates",WEDIT_XML_View)
	
ELSE
	// Can't find the XML!
	Info("The requested data feed cannot be located!")
	RETURN
END

// Look for the first 2 title tags and ignore them as they are just headers
XMLFind("ExRates","title",XMLTag)
XMLNext("ExRates")

// This is the first "real" title tag with a country code and rate
XMLNext("ExRates")

// Loop to process the rest of the tags
WHILE XMLFound("ExRates")

	// Move the current title tag data to a work variable
	glocalsTempstring = XMLData("ExRates")
	
	// Get currency code from the XML (it's in a fixed position)
	// This will be used later to read the country/currency table
	glocalsTempcurrency = Middle(glocalsTempstring,9,3)
	
	// Get exchange rate from the XML - it's enclosed in brackets, we need to parse char-by-char
	// Set the parse start point and clear the temp rate variable
	glocaliTempcount = 14
	glocalsTemprate = ""
	
	// Loop to extract the exchange rate - it's variable length
	// Parse the XML title data tag contents from tempcount (=14) 'til we reach the ")" bracket - this is the end of the rate data
	WHILE Middle(glocalsTempstring,glocaliTempcount,1) <> ")"
		
		// Save the character we are currently processing to avoid keep using the Middle function
		glocalcTempChar = Middle(glocalsTempstring,glocaliTempcount,1)
		
		// Ignore commas when parsing - they're not good when moving directly to a numeric field
		IF glocalcTempChar = "," THEN
			glocaliTempcount++	
		ELSE
			// Not a comma, so append the next digit to the exchange rate 
			glocalsTemprate = glocalsTemprate + glocalcTempChar
			glocaliTempcount++	
		END
	END
	
	// Now that we have the exchange rate, read the country table based on the currency code
       HReadSeek(Country,cCurrencyCode,glocalsTempcurrency)
        	
	// Set the country/currency exchange rate
	Country.nCurrencyRate = glocalsTemprate

	// Set the Last Updated Timestamp
	Country.dtCurrUpdated = DateSys() + TimeSys()
		
	// Modify the country/currency file with this new exchange rate
	HModify(Country)
		
	// Get the next country/currency as (in my implemtation) there are likely to be several countries using this currency (e.g. Euro)
	HReadNext(Country,cCurrencyCode)
		
	// Okay to continue?
	IF HFound(Country) THEN
			
		// Enter a loop to process countries using the same currency and drop out of loop when the currency changes
		WHILE Country.cCurrencyCode = glocalsTempcurrency
				
			// Set the exchange rate
			Country.nCurrencyRate = glocalsTemprate
			
			// Set the Last Updated Timestamp
			Country.dtCurrUpdated = DateSys() + TimeSys()
			
			// Modify the country file with this new exchange rate
			HModify(Country)
			
			// Get the next country/currency as there are likely to be several countries using the currency (e.g. Euro)
			HReadNext(Country,cCurrencyCode)
			
		END		
	END
			
	// Continue processing by finding the next title tag
	XMLNext("ExRates")
END

// The end...
XMLCancelSearch("ExRates")

Glenn Rathke
Re: Try web service on exchange rates - windev
November 20, 2008 04:26AM
Thanks to you and Fabrice for your explanatoin and sample.

Using HTTPRequest with HTTPGetResult() and the XML functions makes it super simple to retrieve the data.

Glenn
Author:

Your Email:


Subject:


Spam prevention:
Please, enter the code that you see below in the input field. This is for blocking bots that try to post this form automatically. If the code is hard to read, then just try to guess it right. If you enter the wrong code, a new image is created and you get another chance to enter it right.
Message: