------解决方案--------------------
xml 反序列化成 List<class> 绑定到 Grid 上
------解决方案--------------------
------解决方案-------------------- 用DataSet.ReadXml(); 然后用DataSet绑定界面控件!
------解决方案--------------------
根据xml结构 恰好 可以先 封装成3个 类 public class School : List<Grade> {} public class Grade { public Grade() { Classes = new List<Class>(); } public string Name { get; set; } public int Id { get; set; } public List<Class> Classes { get; set; } }
public class Class { public string Name { get; set; } public int Id { get; set; } public int Student { get; set; } }
然后把得到的xml反序列化出来 public T Deserialize<T>(string content) { XmlSerializer xmlSerializer = new XmlSerializer(typeof(T)); using (Stream stream = new MemoryStream(Encoding.Default.GetBytes(content))) { T obj = default(T); try { obj = (T)xmlSerializer.Deserialize(stream); } catch { obj = default(T); } return obj; } }
调用 School school = school.Deserialize<School>(content);