Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- using System.Net.Http;
- using System.Threading.Tasks;
- using HtmlAgilityPack;
- namespace XMLParser
- {
- class Program
- {
- static async Task Main(string[] args)
- {
- double usdPrice, eurPrice;
- var url = @"https://www.cbr-xml-daily.ru/daily.xml";
- var rawHtml = await new HttpClient().GetStringAsync(url);
- var doc = new HtmlDocument();
- doc.LoadHtml(rawHtml);
- var valutes = doc.DocumentNode.ChildNodes["ValCurs"].ChildNodes;
- foreach (var valute in valutes)
- {
- var charCode = valute.ChildNodes["CharCode"].InnerText;
- var price = valute.ChildNodes["Value"].InnerText;
- if (charCode == "USD")
- {
- usdPrice = double.Parse(price);
- Console.WriteLine($"1 {charCode} = {usdPrice}");
- }
- else if (charCode == "EUR")
- {
- eurPrice = double.Parse(price);
- Console.WriteLine($"1 {charCode} = {eurPrice}");
- }
- }
- ;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement