wince xml 配置文件设置,直接上源码

public static class ConfigManager
{
private static string configName="app.xml";
private static string XMLPath = "";
private static XmlDocument xmlIAUConfig;
public static XmlDocument XMLIAUConfig
{
get { return xmlIAUConfig; }
set { xmlIAUConfig = value; }
}
private static string platForm;
private static string PlatForm
{
get
{
return Environment.Osversion.Platform.ToString();
}
}
private static string currentPath;
public static string CurrentPath
{
get
{
if (PlatForm.Equals("WinCE"))
{
currentPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase);
}
else if (PlatForm.Equals("Win32NT"))
{
currentPath = Directory.GetCurrentDirectory();
}

return currentPath;
}
}

static ConfigManager()
{
xmlIAUConfig = new XmlDocument();
XMLPath = CurrentPath;
Int32 i = XMLPath.LastIndexOf("/");
if (i >= 0)
XMLPath = XMLPath.Remove(i);
XMLPath = XMLPath + "//"+configName;
xmlIAUConfig.Load(XMLPath);
}

public static String GetValue(String key)
{
xmlIAUConfig.Load(XMLPath);
String value;
String path = @"//DataAccess/appSettings/add[@key='" + key + "']";
XmlNodeList xmlAdds = xmlIAUConfig.SelectNodes(path);

if (xmlAdds.Count == 1)
{
XmlElement xmlAdd = (XmlElement)xmlAdds[0];

value = xmlAdd.GetAttribute("value");
}
else
{
throw new Exception("IAUConfig配置信息设置错误:键值为" + key + "的元素不等于1");
}

return value;
}
public static void SavaConfig(string strKey,string strValue)
{
XmlDocument XMLDoc = new XmlDocument();
XMLDoc.Load(configName);
XmlNodeList list = XMLDoc.GetElementsByTagName("add");

for (int i = 0; i < list.Count; i++) { if (list[i].Attributes[0].Value == strKey) { list[i].Attributes[1].Value = strValue; } } StreamWriter swriter = new StreamWriter(configName); XmlTextWriter xw = new XmlTextWriter(swriter); xw.Formatting = Formatting.Indented; XMLDoc.Writeto(xw); xw.Close(); swriter.Close(); } }

相关文章

php输出xml格式字符串
J2ME Mobile 3D入门教程系列文章之一
XML轻松学习手册
XML入门的常见问题(一)
XML入门的常见问题(三)
XML轻松学习手册(2)XML概念