Click here to Skip to main content
12,996,261 members (64,196 online)
Click here to Skip to main content
Add your own
alternative version


32 bookmarked
Posted 5 Apr 2005

WEBCLIENT to “European Central Bank” to calculated Exchange between countries.

, 15 Apr 2005
Rate this:
Please Sign up or sign in to vote.
This load the "ECB" xml file and parse it into a dataset. From that we can calculated the Exchange rate between difference countries.

Sample image


The ECB very conveniently (and for free) gives daily the exchange rates of the most

common currencies, in several file formats, among which an XML file for parsing. (Shortened copy below)

<?xml version="1.0" encoding="UTF-8"?>
<gesmes:Envelope xmlns:gesmes="" xmlns="">
<gesmes:subject>Reference rates</gesmes:subject>
<gesmes:name>European Central Bank</gesmes:name>
<Cube time='2004-03-11'>
<Cube currency='USD' rate='1.2256'/>
<Cube currency='JPY' rate='135.58'/>
<Cube currency='DKK' rate='7.4518'/>
<Cube currency='ZAR' rate='8.2441'/>

Since this is a free resource, then this allow me to post also the URI for the XML file:

I will make a Windows Application there was working as a Web Client to "ECB" XML.

From real rate of exchange from European Central Bank making a calculator to calculated the rate of Exchange between difference countries.


The basic ideas are to get make a program to calculated the rate between difference countries. The European Central Bank dispose the a XML file over the typical

trade countries exchange rate. From this I can calculated how many money I have to pay for a product. Just remember, that we can only get the

exchange rate for the actual day when Bank is closed about 4 o'clock.

Using the code

Microsoft working with an XmlTextReader there can read from any kind of XML file.

But the ECB xml file is not a real web services so I want to parse it to a Dataset descript se below.

On this side can the index lists currency ISO codes by

country and precious metal. You can also find an ISO currency code by code. See picture how Web Client works.


Sample image

I Store the parsing data into a dataset, see picture.

From this dataset I can find and get data, so on.

Sample image


private ExchanceRate parseWebXML(string WebAddress)
	XmlTextReader xmlReader;

	ExchanceRate dsVa = new ExchanceRate();

	DataRow newRowVa = null;

		//Read data from the XML-file over the interNET
		xmlReader = new XmlTextReader(WebAddress);
	catch( WebException )
		throw new WebException("There has been a mistake with collect the xmlfile from the net!");

		while( xmlReader.Read() )
			if (xmlReader.Name != "")
				//Check that there are node call gesmes:name
				if (xmlReader.Name == "gesmes:name") 
					_author = xmlReader.ReadString();
				for (int i = 0 ; i < xmlReader.AttributeCount; i++)
					//Check that there are node call Cube
					if (xmlReader.Name == "Cube") 
						//Check that there are 1 attribut, then get the date
						if (xmlReader.AttributeCount == 1)

							DateTime tim = DateTime.Parse(xmlReader.Value);
							newRowVa = null;
							DataRow newRowCo = null;

							newRowVa = dsVa.Exchance.NewRow();
							newRowVa["Date"]= tim;

							newRowCo = dsVa.Country.NewRow();
							newRowCo["Initial"]= "EUR";
							newRowCo["Name"]= convert.MoneyName("EUR");		// Find Country name from ISO code
							newRowCo["Rate"]= 1.0;

							newRowCo.SetParentRow(newRowVa);	// Make Key to subtable

						//If the number of attributs are 2, so get the ExchangeRate-node
						if (xmlReader.AttributeCount == 2)
							string cur = xmlReader.Value;
							decimal rat = decimal.Parse(xmlReader.Value.Replace(".",",")); // I am using "," as a decimal symbol

							DataRow newRowCo = null;

							newRowCo = dsVa.Country.NewRow();
							newRowCo["Initial"]= cur;
							newRowCo["Name"]= convert.MoneyName(cur);
							newRowCo["Rate"]= rat;


	catch( WebException )
		throw new WebException("connections lost");

	return dsVa;

Here I can calculated the Exchange between difference countries from the Exchange rate.

private static double ExRateValue(double Input, double FromContry, double ToContry)
	double result = 0;
	if( FromContry == 0 ) return 0;
	result = (Input/FromContry)*ToContry;
	result = Math.Round(result,2);

	return result;


In this article has been shown one simple way how to implement a solution for connecting over Internet.

I used the power of .Net Technologies such as Web client in the XmlTextReader.

Remember that using this link it get data back from start of the Europe Central Bank history 01/04/1999,

and on mine computer it take ½ second to load the xml and parse the data to mine dataset.

Good luck.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Software Developer (Senior) Lessor A/S
Denmark Denmark
I have working with C since 1988, and updates to VC++ in 1998. The first software I was making in VC++ was Fan calculation program with graph. This Fan Was integrated with the Oracle system.
I've been working almost exclusively with C# and .NET since
beginning of the technology.
Now I am working with Web API and CRM, MVC 5.0, SQL Server, C# and .NET. The company Lessor A/S is a IT/Finans house.
In my work, I have gained extensive experience with web security. ADFS etc..
Have also gained experience with DevOps CI and automatic deployment

You may also be interested in...

Comments and Discussions

QuestionHI, I modified the parseWebXml.... Pin
sushiBite6-Dec-11 4:33
membersushiBite6-Dec-11 4:33 
AnswerRe: HI, I modified the parseWebXml.... Pin
hestol8-Dec-11 0:31
memberhestol8-Dec-11 0:31 
Generalprevious days Pin
AndrusM7-Jan-11 10:09
memberAndrusM7-Jan-11 10:09 
AnswerRe: previous days Pin
hestol16-Jan-11 23:19
memberhestol16-Jan-11 23:19 
GeneralRe: previous days Pin
AndrusM16-Jan-11 23:26
memberAndrusM16-Jan-11 23:26 
AnswerRe: previous days Pin
hestol17-Jan-11 2:31
memberhestol17-Jan-11 2:31 
GeneralGreat, but... Pin
gggggg29-Nov-05 0:33
membergggggg29-Nov-05 0:33 
GeneralPictures are not displayed Pin
toticow6-Apr-05 1:07
membertoticow6-Apr-05 1:07 
GeneralRe: Pictures are not displayed Pin
hestol15-Apr-05 2:46
memberhestol15-Apr-05 2:46 
GeneralRe: Pictures are not displayed Pin
drutch6-Dec-07 5:45
memberdrutch6-Dec-07 5:45 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.170609.2 | Last Updated 15 Apr 2005
Article Copyright 2005 by hestol
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid