将XML文件读取 绑定数据至Dictionary
Eg: Xml文件
<?xml version="1.0" encoding="utf-8" ?>
<LanguageConfig>
<Chinese></Chinese>
<English>002</English>
<Simplified>003</Simplified>
<Traditional>001,008</Traditional>
</LanguageConfig>
设定字典格式为Dictionary<string,List
var dic = new Dictionary<string, List<string>>();
XmlDocument xml = new XmlDocument();
var path = AppDomain.CurrentDomain.BaseDirectory + "\\LanguageConfig.xml";//文件所在路径
xml.Load(path);
XmlElement root = xml.DocumentElement;
foreach (XmlNode item in root.ChildNodes)
{
if (!string.IsNullOrWhiteSpace(item.InnerText))
{
if (!dic.ContainsKey(item.Name))
{
var values = item.InnerText.Split(",").ToList();
dic.Add(item.Name,values);
}
}
}
结果格式