2016-07-06 105 views
-3

嗨我試圖從以下網站獲取匯率數據到我的C#應用​​程序。如果您在下面的鏈接中向下滾動,則有一個開發人員部分,代碼使用PHP。我不知道這是否可以在C#中實現,因爲我是PHP新手。PHP到C#兌換貨幣匯率

任何幫助不同的方式來實現這個或如何使這個PHP代碼在我的C#應用​​程序的作品。由於這是官方的歐元匯率,因此使用本網站非常重要。

http://www.ecb.europa.eu/stats/exchange/eurofxref/html/index.en.html

我怎樣才能提取數據,並從我的C#應用​​程序

<gesmes:Envelope xmlns:gesmes="http://www.gesmes.org/xml/2002-08-01" xmlns="http://www.ecb.int/vocabulary/2002-08-01/eurofxref"> 
<gesmes:subject>Reference rates</gesmes:subject> 
<gesmes:Sender> 
<gesmes:name>European Central Bank</gesmes:name> 
</gesmes:Sender> 
<Cube> 
<Cube time="2016-07-05"> 
<Cube currency="USD" rate="1.1146"/> 
<Cube currency="JPY" rate="113.50"/> 
</Cube> 
</Cube> 
</gesmes:Envelope> 
+1

我們是不是免費的代碼轉換服務。 – Epodax

+0

正如@Epodax指出的那樣,Stack Overflow可以幫助解決特定問題,而不是像這樣的開放式問題。請參閱「我可以在這裏詢問什麼主題?」頁面(http://stackoverflow.com/help/on-topic),其中提到的問題「必須包括您迄今爲止解決問題所做的工作摘要,並描述瞭解決問題的難度「。 –

回答

0

只是快速和骯髒的管理這些數據:

using (var webClient = new WebClient()) 
{ 
    var xml = webClient.DownloadString("http://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml"); 
    var xmlDoc = new XmlDocument(); 
    xmlDoc.LoadXml(xml); 
    foreach (XmlElement child in xmlDoc.DocumentElement.ChildNodes[2].ChildNodes[0]) 
    { 
    var currency = child.Attributes[0].InnerText; 
    var rate = child.Attributes[1].InnerText; 
    Console.WriteLine("1€={0} {1}", rate, currency); 
    } 
}