public List<EnSurgery> listSurgery()
{
List<EnSurgery> list = new List<EnSurgery>();
string xmlFilePath = "XMLSurgery.xml";
if (!string.IsNullOrEmpty(xmlFilePath))
{
//string path = HttpContext.Current.Server.MapPath(xmlFilePath);
StringReader StrStream = null;
XmlTextReader Xmlrdr = null;
try
{
XmlDocument xmldoc = new XmlDocument();
//根据地址加载Xml文件
xmldoc.Load(xmlFilePath);
DataSet ds = new DataSet();
//读取文件中的字符流
StrStream = new StringReader(xmldoc.InnerXml);
//获取StrStream中的数据
Xmlrdr = new XmlTextReader(StrStream);
//ds获取Xmlrdr中的数据
ds.ReadXml(Xmlrdr);
foreach (DataTable itemTable in ds.Tables)
{
foreach (DataRow item in itemTable.Rows)
{
EnSurgery en = new EnSurgery();
en.ID = item["id"].ToString();
en.Name = item["Name"].ToString();
list.Add(en);
}
}
}
catch (Exception e)
{
throw e;
}
finally
{
//释放资源
if (Xmlrdr != null)
{
Xmlrdr.Close();
StrStream.Close();
StrStream.Dispose();
}
}
}
else
{
return null;
}
return list;
}