public void SetKeyValue(string key, string value)
{
if (key == null || key == string.Empty)
{
throw new ApplicationException("Required key is blank or null");
}
if (value == null)
{
throw new ApplicationException("Required value is null");
}
XmlNode node = GetKeyValueNode(key);
if (node == null)
{
XmlNode top = XmlDocument.SelectSingleNode("/configuration");
if (top == null)
{
top = XmlDocument.AppendChild(XmlDocument.CreateElement("configuration") );
}
XmlNode app = top.SelectSingleNode("appSettings");
if (app == null)
{
app = top.AppendChild(XmlDocument.CreateElement("appSettings") );
}
node = app.AppendChild(XmlDocument.CreateElement("add") );
node.Attributes.Append(XmlDocument.CreateAttribute("key") ).InnerText = key;
node.Attributes.Append(XmlDocument.CreateAttribute("value") );
}
node.Attributes["value"].InnerText = value;
}