Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- List<Employee> lstEmployee
- --------Start Code after this line ---------------------
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Xml.Linq;
- using System.Text;
- namespace ConsoleApp4
- {
- class Program
- {
- public static bool Name { get; private set; }
- static void Main(string[] args)
- {
- var filename = "sample.xml";
- var fileDirectory = "C:\Users\userdirectory\Desktop\test\";
- string setFilePath = Path.Combine(fileDirectory, filename);
- Console.WriteLine(setFilePath);
- XDocument xdoc1 = XDocument.Load(setFilePath);
- Employee objEmployee = new Employee();
- List<Employee> lstEmployee
- = (from _employee in xdoc1.Element("Staff").Elements("Employee")
- select new Employee
- {
- EmpId = _employee.Element("EmpId").Value,
- Name = _employee.Element("Name").Value,
- Sex = _employee.Element("Sex").Value,
- Phone = _employee.Element("Phone").Value,
- objAddress = (from _address in _employee.Elements("Address")
- select new Address
- {
- Street = _address.Element("Street").Value,
- City = _address.Element("City").Value,
- State = _address.Element("State").Value,
- Zip = _address.Element("Zip").Value,
- Country = _address.Element("Country").Value
- }).FirstOrDefault(),
- }).ToList();
- foreach (var _stud in lstEmployee)
- {
- Console.WriteLine(_stud.Name);
- }
- Console.ReadLine();
- }
- }
- }
Add Comment
Please, Sign In to add comment