This article describes the method of converting Dictionary to XML files in C#. Share it for your reference. The specific implementation method is as follows:
The following is the xml file:
<nodes>
<Land and Resources Bureau>
<name>Municipal Bureau Land and Resources Bureau</name>
<code>330</code>
<Accepted telephone="88205156">Ping, Qian</Accepted>
<Audit personId="48e1bca3-b0f5d0fec89">Friends</Audit>
<Adjustment>123</Adjustment>
<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>
<Accepted telephone="13819655058">Chen</Accepted>
<Audit personId="f7351d0f-b197-0a0fc685f3ac">Hui</Audit>
<Adjustment>456</Adjustment>
<BELONGSYSTEM>123</BELONGSYSTEM>
<DEPTID>00100033</DEPTID>
<SERVICECODE>
204cdd0b
</SERVICECODE>
</Land and Resources Bureau>
</nodes>
Here are the relevant methods to obtain:
/// Obtain acceptance information
/// </summary>
/// <param name="p_shixianCode">City and County Code</param>
/// <returns>Acceptance information</returns>
public static Dictionary<string,string> ShouLiInfo(string p_shixianCode)
{
XDocument xd = null;
string xmlPath = "";
xd = (xmlPath);//xml storage path
Dictionary<string, string> pDic = new Dictionary<string, string>();
var info = from t in ("Home Office").Where(p => ("code").Value == p_shixianCode) select new { name = ("name").Value, code = ("code").Value, shouli = ("Accepted").Value, telephone = ("Accepted").Attribute("telephone").Value, shenhe = ("Accepted").Value, personId = ("Accepted").Attribute("personId").Value, shending = ("Accepted").Value, DEPTID = ("DEPTID").Value, BELONGSYSTEM = ("BELONGSYSTEM").Value, SERVICECODE = ("SERVICECODE").Value };
foreach (var item in info)
{
("name", );
("code", );
("shouliPerson", );
("telephone", );
("shenhePerson", );
("shenhepersonId", );
("shendingPerson", );
("DEPTID", );
("BELONGSYSTEM", );
("SERVICECODE", );
}
return pDic;
}
That's it, just call the method
I hope this article will be helpful to everyone's C# programming.