C#針對xml檔案轉化Dictionary的方法

來源:互聯網
上載者:User

標籤:資訊   資料類型   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






相關內容WinForm通過操作註冊表實現限制軟體使用次數的方法C#實現在應用程式間發送訊息的方法樣本C#實現的檔案操作封裝類完整執行個體【刪除,移動,複製,重新命名】當使用者退出點擊瀏覽器後退仍可回到原來頁面的解決方案
基於C#代碼實現九宮格演算法橫豎都等於4C#編程自學之資料類型和變數二C#實現統計字數功能的方法C#使用鉤子獲得按鍵資訊的方法

C#針對xml檔案轉化Dictionary的方法

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.