当前位置: 移动技术网 > IT编程>开发语言>c# > C#针对xml文件转化Dictionary的方法

C#针对xml文件转化Dictionary的方法

2019年07月18日  | 移动技术网IT编程  | 我要评论

新巴黎中文社区,姜玉阳图片,十二影城12yc

本文实例讲述了c#针对xml文件转化dictionary的方法。分享给大家供大家参考。具体实现方法如下:

下面是xml文件:

复制代码 代码如下:
<?xml version="1.0" encoding="utf-8" ?>
<nodes>
<国土局>
<name>市局国土资源局</name>
<code>330</code>
<受理 telephone="88205156">萍,倩</受理>
<审核 personid="48e1bca3-b0f5d0fec89">友</审核>
<审定>123</审定>
<belongsystem>37001</belongsystem>
<deptid>10080100030</deptid>
<servicecode>4e58a6f1</servicecode>
</国土局>
<国土局>
<name>县国土资源局</name>
<code>3321</code>
<受理 telephone="13819655058">晨</受理>
<审核 personid="f7351d0f-b197-0a0fc685f3ac">辉</审核>
<审定>456</审定>
<belongsystem>123</belongsystem>
<deptid>00100033</deptid>
<servicecode>
204cdd0b
</servicecode>
</国土局>
</nodes>

下面是相关的获取方法:

复制代码 代码如下:
/// <summary>
/// 获得受理信息
/// </summary>
/// <param name="p_shixiancode">市县编码</param>
/// <returns>受理信息</returns>
public static  dictionary<string,string> shouliinfo(string p_shixiancode)
{
   xdocument xd = null;
   string xmlpath = "config.xml";
   xd = xdocument.load(xmlpath);//xml存放路径

   dictionary<string, string> pdic = new dictionary<string, string>();
   var info = from t in xd.root.descendants("国土局").where(p => p.element("code").value == p_shixiancode) select new { name = t.element("name").value, code = t.element("code").value, shouli = t.element("受理").value, telephone = t.element("受理").attribute("telephone").value, shenhe = t.element("审核").value, personid = t.element("审核").attribute("personid").value, shending = t.element("审定").value, deptid = t.element("deptid").value, belongsystem = t.element("belongsystem").value, servicecode = t.element("servicecode").value };
   foreach (var item in info)
   {
       pdic.add("name", item.name);
       pdic.add("code", item.code);
       pdic.add("shouliperson", item.shouli);
       pdic.add("telephone", item.telephone);
       pdic.add("shenheperson", item.shenhe);
       pdic.add("shenhepersonid", item.personid);
       pdic.add("shendingperson", item.shending);
       pdic.add("deptid", item.deptid);
       pdic.add("belongsystem", item.belongsystem);
       pdic.add("servicecode", item.servicecode);
   }
   return pdic;
}


  

就这样啦就可以了,直接调用该方法就可以啦

希望本文所述对大家的c#程序设计有所帮助。

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网