马上加入IBC程序猿 各种源码随意下,各种教程随便看! 注册 每日签到 加入编程讨论群

C#教程 ASP.NET教程 C#视频教程程序源码享受不尽 C#技术求助 ASP.NET技术求助

【源码下载】 社群合作 申请版主 程序开发 【远程协助】 每天乐一乐 每日签到 【承接外包项目】 面试-葵花宝典下载

官方一群:

官方二群:

ASP.NET如何读取XML文件

[复制链接]
查看3777 | 回复0 | 2012-11-29 17:12:09 | 显示全部楼层 |阅读模式
XML小数据库是我们离不开的文件,那我们如何读取XML的文件呢?代码如下:
  1.     DataTable DataSource(string xmlFile)
  2.   {
  3.   DataSet objDs = new DataSet();
  4.   //假设xml文件放在App_Data目录下
  5.   objDs.ReadXml(HttpContext.Current.Server.MapPath("~/App_Data/" + xmlFile));
  6.   return objDs.Tables[0];
  7.   }
  8.   string GetFeildText(DataTable dt, string condition, string outPutFieldText)
  9.   {
  10.   string result = string.Empty;
  11.   DataRow[] row = dt.Select(condition);
  12.   if (row.Length > 0)
  13.   result = row[0][outPutFieldText].ToString();
  14.   return result;
  15.   }
  16.   //假设需求是:根据id找name
  17.   string GetSexName(string id)
  18.   {
  19.   string condition = "id= '" + id+ "'";
  20.   return GetFeildText(DataSource(), condition, "name");
  21.   }
复制代码
C#论坛 www.ibcibc.com IBC编程社区
C#
C#论坛
IBC编程社区
*滑块验证:
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则