码迷,mamicode.com
首页 > Windows程序 > 详细

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

时间:2017-12-07 00:04:43      阅读:333      评论:0      收藏:0      [点我收藏+]

标签:信息   数据类型   top   static   efault   har   等于   element   config   

本文实例讲述了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#针对xml文件转化Dictionary的方法

本文地址:  http://www.paobuke.com/develop/c-develop/pbk23189.html






相关内容

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

标签:信息   数据类型   top   static   efault   har   等于   element   config   

原文地址:http://www.cnblogs.com/paobuke/p/7994930.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!