欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

C#針對xml文件轉(zhuǎn)化Dictionary的方法

 更新時間:2015年01月16日 09:10:42   投稿:shichen2014  
這篇文章主要介紹了C#針對xml文件轉(zhuǎn)化Dictionary的方法,是C#操作XML文件的典型應(yīng)用,具有一定參考借鑒價值,需要的朋友可以參考下

本文實例講述了C#針對xml文件轉(zhuǎn)化Dictionary的方法。分享給大家供大家參考。具體實現(xiàn)方法如下:

下面是xml文件:

復(fù)制代碼 代碼如下:
<?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>

下面是相關(guān)的獲取方法:

復(fù)制代碼 代碼如下:
/// <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;
}


  

就這樣啦就可以了,直接調(diào)用該方法就可以啦

希望本文所述對大家的C#程序設(shè)計有所幫助。

相關(guān)文章

最新評論