Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?xml version="1.0" encoding="utf-8" ?>
- <Patients>
- <FirstName>LeBron</FirstName>
- <LastName>James</LastName>
- </Patient>
- <FirstName>Kobe</FirstName>
- <LastName>Bryant</LastName>
- </Patient>
- <FirstName>Allen</FirstName>
- <LastName>Iverson</LastName>
- </Patient>
- </Patients>
- class PatietList : List<Patient>
- {
- public void Load(string xmlFile)
- {
- XDocument doc = XDocument.Load(xmlFile);
- var query = from xElem in doc.Descendants("Patient")
- select new Patient
- {
- EMail = xElem.Attribute("EMail").Value,
- FirstName = xElem.Element("FirstName").Value,
- LastName = xElem.Element("LastName").Value,
- };
- this.Clear();
- AddRange(query);
- }
- public void Save(string xmlFile)
- {
- XElement xml = new XElement("Patients",
- from p in this
- select new XElement("Patient",
- new XAttribute("EMail", p.EMail),
- new XElement("FirstName", p.FirstName),
- new XElement("LastName", p.LastName)));
- xml.Save(xmlFile);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment