Conversion of xml files to Dictionary and xml to dictionary
Below is an xml file
<? Xml version = "1.0" encoding = "UTF-8"?>
<Nodes>
<Land and Resources Bureau>
<Name> Municipal Bureau of Land and Resources </name>
<Code> 330 </code>
<Accepted telephone = "88205156"> Ping, Qian </accepted>
<Review personId = "48e1bca3-b0f5d0fec89"> friends </review>
<Approved> 123 </approved>
<BELONGSYSTEM> 37001 </BELONGSYSTEM>
<DEPTID> 10080100030 </DEPTID>
<SERVICECODE> 4e58a6f1 </SERVICECODE>
</Land and Resources Bureau>
<Land and Resources Bureau>
<Name> County Land and Resources Bureau </name>
<Code> 3321 </code>
<Accept telephone = "13819655058"> morning </accept>
<Review personId = "f7351d0f-b197-0a0fc685f3ac"> Hui </review>
<Approved> 456 </approved>
<BELONGSYSTEM> 123 </BELONGSYSTEM>
<DEPTID> 00100033 </DEPTID>
<SERVICECODE>
204cdd0b
</SERVICECODE>
</Land and Resources Bureau>
</Nodes>
The following describes how to obtain the data:
/// <Summary> /// obtain the acceptance information /// </summary> /// <param name = "p_shixianCode"> City/County Code </param> /// <returns> acceptance Information </returns> public static Dictionary <string, string> ShouLiInfo (string p_shixianCode) {XDocument xd = null; string xmlPath = "config. xml "; xd = XDocument. load (xmlPath); // The xml storage path Dictionary <string, string> pDic = new Dictionary <string, string> (); var info = from t in xd. root. descendants ("Land and Resources Bureau "). where (p => p. element ("code "). value = p_shixianCode) select new {name = t. element ("name "). value, code = t. element ("code "). value, shouli = t. element ("accept "). value, telephone = t. element ("accept "). attribute ("telephone "). value, shenhe = t. element ("Review "). value, personId = t. element ("Review "). attribute ("personId "). value, shending = t. element ("approved "). 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;
}
You can call this method directly.