public void Save(List<Cat> cat_list) { Convert_cat_xml_dom conv = new Convert_cat_xml_dom(); XmlDocument doc = conv.toXML(cat_list); XmlTextWriter xw = new XmlTextWriter(path_to_file, Encoding.UTF8); xw.Formatting = Formatting.Indented; doc.Save(xw); xw.Close(); }
public List<Cat> Load() { List<Cat> cat_list_out = new List<Cat>(); FileStream fs = new FileStream(path_to_file, FileMode.OpenOrCreate); StreamReader sr = new StreamReader(fs, Encoding.UTF8); string buf; StringBuilder xml_string = new StringBuilder(); while ((buf = sr.ReadLine()) != null) { xml_string.Append(buf); } XmlDocument doc = new XmlDocument(); doc.LoadXml(xml_string.ToString()); Convert_cat_xml_dom conv = new Convert_cat_xml_dom(); foreach(XmlElement item in doc.DocumentElement.ChildNodes) { cat_list_out.Add(conv.fromNode(item)); } sr.Close(); fs.Close(); return cat_list_out; }