public Dictionary<string, string> GetXml()
{
Dictionary<string, string> dic = new Dictionary<string, string>();
string filePath = System.Web.HttpContext.Current.Server.MapPath(string.Concat("", "TestDemo.xml"));
if (System.IO.File.Exists(filePath))
{
XmlDocument XmlDoc = new XmlDocument();
XmlDoc.Load(filePath);
XmlNodeList nodes = XmlDoc.SelectNodes("roots/data");
foreach (XmlNode node in nodes)
{
string key = node.Attributes["name"].Value.ToString();
string value = node.SelectSingleNode("value").InnerText;
dic.Add(key, value);
}
}
return dic;
}

Demo中xml文件结点如下,可以根据不同xml文件结构改相应的代码。

 <root>
<data name="Name" xml:space="preserve">
<value>IT民工-杰</value>
</data>
<data name="Title" xml:space="preserve">
<value>他是中国最帅程序员</value>
</data>
</root>
04-06 02:14