本文實例講述了C#針對xml文件轉化Dictionary的方法。分享給大家供大家參考。具體實現方法如下:
下面是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#程序設計有所幫助。
新聞熱點
疑難解答