/ Published in: C#

Expand |
Embed | Plain Text
<?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) { from p in this xml.Save(xmlFile); } }
You need to login to post a comment.