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

这篇文章主要介绍了C#针对xml文件转化Dictionary的方法,是C#操作XML文件的典型应用,具有一定参考借鉴价值,需要的朋友可以参考下

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

下面是xml文件:

复制代码 代码如下:


<国土局>
市局国土资源局
330
<受理 telephone="88205156">萍,倩
<审核 personId="48e1bca3-b0f5d0fec89">友
<审定>123
37001
10080100030
4e58a6f1

<国土局>
县国土资源局
3321
<受理 telephone="13819655058">晨
<审核 personId="f7351d0f-b197-0a0fc685f3ac">辉
<审定>456
123
00100033

204cdd0b


下面是相关的获取方法:

复制代码 代码如下:
///
/// 获得受理信息
///

/// 市县编码
/// 受理信息
public static  Dictionary ShouLiInfo(string p_shixianCode)
{
   XDocument xd = null;
   string xmlPath = "config.xml";
   xd = XDocument.Load(xmlPath);//xml存放路径

   Dictionary pDic = new Dictionary();
   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#针对xml文件转化Dictionary的方法的详细内容,更多请关注0133技术站其它相关文章!

赞(0) 打赏
未经允许不得转载:0133技术站首页 » 其他教程