private Price GetPrice() { Price price = new Price(); var articles = new List <Price.Article>(); try { XmlNode elements = this.document.GetElementsByTagName("price").Item(0); foreach (XmlNode element in elements) { if (element.Name == "total") { price.Total = Int32.Parse(element.InnerText); } else if (element.Name == "tax") { price.Tax = Int32.Parse(element.InnerText); } else if (element.Name == "articles") { Price.Article article = new Price.Article(); foreach (XmlNode art in element.ChildNodes) { if (art.Name == "code") { article.Code = Int32.Parse(art.InnerText); } else if (art.Name == "name") { article.Name = art.InnerText; } else if (art.Name == "price") { article.PriceField = Double.Parse(art.InnerText); } articles.Add(article); } } } price.Articles = articles; } catch (Exception ex) { Console.WriteLine($"Произошла ошибка при парсинге элемента Price."); throw ex; } return(price); }
private SoldSeat GetSoldSeat() { SoldSeat soldSeat = new SoldSeat(); XmlNode elements = this.document.GetElementsByTagName("sold_seats").Item(0); foreach (XmlNode element in elements) { switch (element.Name) { case "passenger": { Passenger passenger = new Passenger(); foreach (XmlNode item in element.ChildNodes) { switch (item.Name) { case "name": { passenger.Name = item.InnerText; break; } case "surname": { passenger.SurName = item.InnerText; break; } } } soldSeat.Passenger = passenger; break; } case "id": { soldSeat.Id = Int32.Parse(element.InnerText); break; } case "car_id": { soldSeat.CarId = Int32.Parse(element.InnerText); break; } case "tos_id": { soldSeat.TosId = Int32.Parse(element.InnerText); break; } case "price": { Price price = new Price(); var articles = new List <Price.Article>(); foreach (XmlNode item in element.ChildNodes) { if (item.Name == "total") { price.Total = Int32.Parse(item.InnerText); } else if (item.Name == "tax") { price.Tax = Int32.Parse(item.InnerText); } else if (item.Name == "articles") { Price.Article article = new Price.Article(); foreach (XmlNode art in item.ChildNodes) { if (art.Name == "code") { article.Code = Int32.Parse(art.InnerText); } else if (art.Name == "name") { article.Name = art.InnerText; } else if (art.Name == "price") { article.Price = Double.Parse(art.InnerText); } articles.Add(article); } } } soldSeat.Price = price; break; } } } return(soldSeat); }