Guest User

Untitled

a guest
Nov 18th, 2017
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.75 KB | None | 0 0
  1. Customer newCustomer = new Customer();
  2. Console.WriteLine("Please Enter new Customer Id");
  3. int id = Convert.ToInt32(Console.ReadLine());
  4. Console.WriteLine("Please Enter The Customers First Name:");
  5. string firstName = Console.ReadLine();
  6. Console.WriteLine("Please Enter The Customers Surname:");
  7. string lastName = Console.ReadLine();
  8. Console.WriteLine("Please Enter a Contact Telephone Number:");
  9. string phoneNumber = Console.ReadLine();
  10. Console.WriteLine("Please Enter The First Line of the Delivery Address:");
  11. string firstLineAddress = Console.ReadLine();
  12. Console.WriteLine("Please Enter Second Line of the Address:");
  13. string secondLineAddress = Console.ReadLine();
  14. Console.WriteLine("Please Enter Town / City:");
  15. string townCity = Console.ReadLine();
  16. Console.WriteLine("Please Enter Postcode");
  17. string postCode = Console.ReadLine();
  18. Console.WriteLine("Please Enter Customers Email Address");
  19. string emailAddress = Console.ReadLine();
  20. XDocument doc = new XDocument(new XDeclaration("1.0", "utf-8", "yes"),
  21. new XComment("Customer Database"),
  22. new XElement("customer", new XAttribute("CustomerId", id),
  23. new XElement("firstName", firstName),
  24. new XElement("lastName", lastName),
  25. new XElement("firstLineAddress", firstLineAddress),
  26. new XElement("secondLineAddress", secondLineAddress),
  27. new XElement("cityTown", townCity),
  28. new XElement("postCode", postCode),
  29. new XElement("phoneNumber", phoneNumber),
  30. new XElement("emailAddress", emailAddress)));
  31. doc.Save("CustomerDatabase\Customer.xml");
  32.  
  33. <?xml version="1.0" encoding="utf-8"?>
  34. <customer>...</customer>
  35. <?xml version="1.0" encoding="utf-8"?>
  36. <customer>...</customer>
  37.  
  38. <?xml version="1.0" encoding="utf-8"?>
  39. <customers>
  40. <customer>...</customer>
  41. <customer>...</customer>
  42. </customers>
  43.  
  44. var newCustomer = new XElement("customer", new XAttribute("CustomerId", id),
  45. new XElement("firstName", firstName),
  46. new XElement("lastName", lastName),
  47. new XElement("firstLineAddress", firstLineAddress),
  48. new XElement("secondLineAddress", secondLineAddress),
  49. new XElement("cityTown", townCity),
  50. new XElement("postCode", postCode),
  51. new XElement("phoneNumber", phoneNumber),
  52. new XElement("emailAddress", emailAddress)));
  53.  
  54. XDocument doc = XDocument.Load("CustomerDatabase\Customer.xml");
  55. var customers= doc.Element("customers");
  56. customers.Add(newCustomer);
  57. doc.Save("CustomerDatabase\Customer.xml");
Add Comment
Please, Sign In to add comment