private List<model> get()
{
List<model> list = new List<model>();
//加载xml
XmlDocument xml = new XmlDocument();
xml.Load(Server.MapPath("XML.xml"));
//得到xml里的根节点
XmlNode root = xml.DocumentElement;
//便利root里的子节点
foreach (XmlNode n in root.ChildNodes)
{
if (n.Name == "stu")
{
model m = new model();
foreach (XmlNode n1 in n.ChildNodes)
{
if (n1.Name == "name")
{
m.name = n1.InnerText;
}
else if (n1.Name == "age")
{
m.age = int.Parse(n1.InnerText);
}
else if (n1.Name == "sex")
{
m.sex = n1.InnerText;
}
}
list.Add(m);
}
}
return list;
} |