XML小数据库是我们离不开的文件,那我们如何读取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");
-
- }
复制代码 |
|