Guest User

Untitled

a guest
Jan 22nd, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.94 KB | None | 0 0
  1. List<Employee> lstEmployee
  2. --------Start Code after this line ---------------------
  3.  
  4. using System;
  5. using System.Collections.Generic;
  6. using System.IO;
  7. using System.Linq;
  8. using System.Xml.Linq;
  9. using System.Text;
  10.  
  11. namespace ConsoleApp4
  12. {
  13. class Program
  14. {
  15. public static bool Name { get; private set; }
  16.  
  17. static void Main(string[] args)
  18. {
  19.  
  20. var filename = "sample.xml";
  21. var fileDirectory = "C:\Users\userdirectory\Desktop\test\";
  22. string setFilePath = Path.Combine(fileDirectory, filename);
  23. Console.WriteLine(setFilePath);
  24. XDocument xdoc1 = XDocument.Load(setFilePath);
  25. Employee objEmployee = new Employee();
  26. List<Employee> lstEmployee
  27. = (from _employee in xdoc1.Element("Staff").Elements("Employee")
  28. select new Employee
  29. {
  30. EmpId = _employee.Element("EmpId").Value,
  31. Name = _employee.Element("Name").Value,
  32. Sex = _employee.Element("Sex").Value,
  33. Phone = _employee.Element("Phone").Value,
  34. objAddress = (from _address in _employee.Elements("Address")
  35. select new Address
  36. {
  37. Street = _address.Element("Street").Value,
  38. City = _address.Element("City").Value,
  39. State = _address.Element("State").Value,
  40. Zip = _address.Element("Zip").Value,
  41. Country = _address.Element("Country").Value
  42. }).FirstOrDefault(),
  43. }).ToList();
  44. foreach (var _stud in lstEmployee)
  45. {
  46. Console.WriteLine(_stud.Name);
  47. }
  48.  
  49. Console.ReadLine();
  50.  
  51. }
  52. }
  53. }
Add Comment
Please, Sign In to add comment