private void ReadFromXML_Click(object sender, RoutedEventArgs e) { List <Buyer> newBuyersList = new List <Buyer>(); try { XDocument doc = XDocument.Load(@"e:\Обучение\переподготовка\ч.3\курсовая\Project WPF\RealEstataeAgency\RealEstateAgency\bin\Debug\Data.xml"); var root = doc.Root; foreach (var element in root.Elements()) { var buyer = new Buyer(); buyer.BuyerID = int.Parse(element.Element("id").Value); buyer.BuyerName = element.Element("name").Value; buyer.BuyerAdress = element.Element("adress").Value; buyer.BuyerUNP = int.Parse(element.Element("unp").Value); buyer.BuyerPhone = element.Element("phone").Value; buyer.BuyerRequest = element.Element("request").Value; newBuyersList.Add(buyer); } IBuyerRepository buyerXMLRepository = new BuyerRepository(); foreach (var buyerRepo in buyerXMLRepository.GetAll()) { buyerXMLRepository.DeleteBuyer(buyerRepo); } foreach (var buyerXML in newBuyersList) { buyerXMLRepository.AddBuyer(buyerXML); } UpdateSelectedBuyer(); MessageBox.Show("Данные импортированы"); } catch (Exception ex) { MessageBox.Show("Невозможно импортировать данные."); } }