|
|||||||||||||||||
|
|||||||||||||||||
|
Die ECB stellt täglich die aktuellen Wechselkurse zum Euro in einer XML-Datei bereit. http://www.ecb.int/stats/eurofxref/eurofxref-daily.xml Mit der nachfolgenden VB 2008 Klasse zeigen wir Ihnen, wie Sie die XML Struktur von der Webseite mittels LINQ to XML auslesen können. Das Ergebnis wird als List(Of ECBType) zurückgegeben.
Imports System.Globalization ' ECB Struktur Public Structure ECBType Public ECBCurrency As String Public ECBRate As String Public DisplayName As String End Structure Public Class ECBExchanges Public Function getECBCurrencyExchanges(ByVal WebAddress As String) _ As List(Of ECBType) Try Dim xr As XElement = XElement.Load(WebAddress) Dim xn As XNamespace = xr.Attribute("xmlns").Value Dim xECBs = From ECB In xr.Descendants(xn + "Cube") _ Where ECB.Attribute("currency") IsNot Nothing _ AndAlso ECB.Attribute("rate") IsNot Nothing _ Select New ECBType With { _ .ECBCurrency = ECB.Attribute("currency").Value, _ .ECBRate = ECB.Attribute("rate").Value, _ .DisplayName = CurrencyName(.ECBCurrency)} Return xECBs.ToList Catch ex As Exception Throw ex End Try End Function Private Function CurrencyName(ByVal isoCode As String) As String Dim cultures As CultureInfo() = CultureInfo.GetCultures( _ CultureTypes.SpecificCultures) For Each ci As CultureInfo In cultures Dim ri As New RegionInfo(ci.LCID) If ri.ISOCurrencySymbol = isoCode Then Return ci.DisplayName End If Next Return String.Empty End Function End Class
Nachfolgender Aufruf gibt dann eine List(Of ECBType) zurück: Private MyECB As New ECBExchanges Dim ECBList As List(Of ECBType) = MyECB.getECBCurrencyExchanges( _ "http://www.ecb.int/stats/eurofxref/eurofxref-daily.xml") Letzte Änderung: 04 Oct 2009 at 13:08 Zurück |
|
|||||||||||||||
Powered by:
|
|||||||||||||||||
| (c) 2009 - VB-Power.net | |||||||||||||||||