读取xml数据装配到字典中
2024-10-13 09:52:13
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>
最新文章
- CAN基础知识
- 【py登陆】python模拟登录
- KD-tree
- VBA控件一些属性的解释
- HDU 4046 Panda
- C++封装常用对象和对头文件以及预编译机制的探索
- C# Eval在asp.net中的用法及作用
- C#使用SOAP调用Web Service
- mysql中使用正则表达式时的注意事项
- 京东评论情感分类器(基于bag-of-words模型)
- 通过intent启动Activity
- python编程快速上手之第9章实践项目参考答案
- Linux - 设置/取消代理
- bootstrap时间区间设置方法
- 对cordova插件配置文件plugin.xml的理解
- Consequence of Point-by-Point Bounds
- SSM连接数据库自动生成问题
- 尚硅谷springboot学习30-docker安装mysql示例
- 洛谷P1265 公路修建(Prim)
- 怎样把vector和string数据传给旧的C API
热门文章
- javascript动画系列第三篇——碰撞检测
- 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
- 客户端的验证插件validator
- NET Core-学习笔记(四)
- 年度巨献-WPF项目开发过程中WPF小知识点汇总(原创+摘抄)
- Java中,异常的处理及抛出
- web 前端(轮番插件)
- MongoDB学习笔记六—查询下
- 【一起学OpenFoam】01 OpenFoam的优势
- AutoMapper(五)