程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> C# >> C#入門知識 >> C#針對xml文件轉化Dictionary的辦法

C#針對xml文件轉化Dictionary的辦法

編輯:C#入門知識

C#針對xml文件轉化Dictionary的辦法。本站提示廣大學習愛好者:(C#針對xml文件轉化Dictionary的辦法)文章只能為提供參考,不一定能成為您想要的結果。以下是C#針對xml文件轉化Dictionary的辦法正文


本文實例講述了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#法式設計有所贊助。

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved