ASP.NET读取XML文件

DataTable DataSource(string xmlFile)

{

DataSet objDs = new DataSet();

//假设xml文件放在App_Data目录下

objDs.ReadXml(HttpContext.Current.Server.MapPath("~/App_Data/" + xmlFile));

return objDs.Tables[0];

}

string GetFeildText(DataTable dt, string condition, string outPutFieldText)

{

string result = string.Empty;

DataRow[] row = dt.Select(condition);

if (row.Length > 0)

result = row[0][outPutFieldText].ToString();

return result;

}

//假设需求是:根据id找name

string GetSexName(string id)

{

string condition = "id= '" + id+ "'";

return GetFeildText(DataSource(), condition, "name");

}

posted @ 2011-01-26 18:59  木由水  阅读(199)  评论(0编辑  收藏  举报