C# ile XML dosyası çevirme

Örnek bir kod. Bu mantıktan yola çıkarak türevlerini oluşturabilirsiniz.

C#:
using System;
using System.Net;
using System.Xml;
using System.Windows.Forms;

class Program
{
    static void Main()
    {
        string url = "https://www.tcmb.gov.tr/kurlar/today.xml";

        try
        {
            using (WebClient client = new WebClient())
            {
                string xmlData = client.DownloadString(url);

                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.LoadXml(xmlData);

                XmlNodeList nodes = xmlDoc.GetElementsByTagName("Currency");
                foreach (XmlNode node in nodes)
                {
                    if (node["CurrencyName"].InnerText == "ABD DOLARI")
                    {
                        string dolarKuru = node["ForexSelling"].InnerText;
                        Form form = new Form();
                        Label label = new Label();
                        label.Text = $"Dolar Kuru: {dolarKuru}";
                        form.Controls.Add(label);
                        Application.Run(form);

                        break;
                    }
                }
            }
        }
        catch (Exception ex)
        {
            Console.WriteLine("Hata oluştu: " + ex.Message);
        }
    }
}
 

Yeni konular

Geri
Yukarı