public Dictionary<string, string> GetXml()
{
Dictionary<string, string> dic = new Dictionary<string, string>();
string filePath = System.Web.HttpContext.Current.Server.MapPath(string.Concat("", "TestDemo.xml"));
if (System.IO.File.Exists(filePath))
{
XmlDocument XmlDoc = new XmlDocument();
XmlDoc.Load(filePath);
XmlNodeList nodes = XmlDoc.SelectNodes("roots/data");
foreach (XmlNode node in nodes)
{
string key = node.Attributes["name"].Value.ToString();
string value = node.SelectSingleNode("value").InnerText;
dic.Add(key, value);
}
}
return dic;
}

Demo中xml文件结点如下,可以根据不同xml文件结构改相应的代码。

 <root>
<data name="Name" xml:space="preserve">
<value>IT民工-杰</value>
</data>
<data name="Title" xml:space="preserve">
<value>他是中国最帅程序员</value>
</data>
</root>

最新文章

  1. CAN基础知识
  2. 【py登陆】python模拟登录
  3. KD-tree
  4. VBA控件一些属性的解释
  5. HDU 4046 Panda
  6. C++封装常用对象和对头文件以及预编译机制的探索
  7. C# Eval在asp.net中的用法及作用
  8. C#使用SOAP调用Web Service
  9. mysql中使用正则表达式时的注意事项
  10. 京东评论情感分类器(基于bag-of-words模型)
  11. 通过intent启动Activity
  12. python编程快速上手之第9章实践项目参考答案
  13. Linux - 设置/取消代理
  14. bootstrap时间区间设置方法
  15. 对cordova插件配置文件plugin.xml的理解
  16. Consequence of Point-by-Point Bounds
  17. SSM连接数据库自动生成问题
  18. 尚硅谷springboot学习30-docker安装mysql示例
  19. 洛谷P1265 公路修建(Prim)
  20. 怎样把vector和string数据传给旧的C API

热门文章

  1. javascript动画系列第三篇——碰撞检测
  2. AutoMapper:Unmapped members were found. Review the types and members below. Add a custom mapping expression, ignore, add a custom resolver, or modify the source/destination type
  3. 客户端的验证插件validator
  4. NET Core-学习笔记(四)
  5. 年度巨献-WPF项目开发过程中WPF小知识点汇总(原创+摘抄)
  6. Java中,异常的处理及抛出
  7. web 前端(轮番插件)
  8. MongoDB学习笔记六—查询下
  9. 【一起学OpenFoam】01 OpenFoam的优势
  10. AutoMapper(五)