1> 先调用AnalisisXml(str,node);
str:xml字符串
node:根节点(ps:xml)
2> 取值:AppSettings.Get(key)
key:键名
3>注意引用集合命名空间
using System.Collections.Specialized;
using System.Xml;
class CCB_CommonPlatform
{
private NameValueCollection appSettings = new NameValueCollection();
public NameValueCollection AppSettings
{
get
{
return appSettings;
}
}
public void AnalysisXml(string pm_configFile, string pm_Notes)
{
string notes = "";
if (pm_Notes != null)
{
notes = pm_Notes;
}
try
{
AppSettings.Clear();
XmlDocument myXmlDocument = new XmlDocument();
myXmlDocument.LoadXml(pm_configFile);
foreach (XmlNode appSettingNode in myXmlDocument.SelectNodes(notes))
{
foreach (XmlNode Node in appSettingNode.ChildNodes)
{
this.AppSettings.Add(Node.Name, Node.InnerText);
}
}
}
catch
{
throw new Exception(pm_configFile);
}
}
}