public void SaveParam(ParamInfo param) { XmlDocument doc = GetXmlDocumentByFileName(DbParamsFile); XmlNodeList nodeList = doc.GetElementsByTagName("Params"); if (nodeList.Count > 0) { XmlNode root = nodeList[0]; bool hasParam = false; foreach (XmlNode node in root.ChildNodes) { ParamInfo tmp = ParamInfo.LoadByXmlNode(node); param.ItsNode = tmp.ItsNode; if (tmp.Key.Equals(param.Key, StringComparison.OrdinalIgnoreCase)) { param.SetNodeValue(); hasParam = true; break; } } if (!hasParam && param.ItsNode != null) { param.ItsNode = param.ItsNode.Clone(); param.SetNodeValue(); root.AppendChild(param.ItsNode); } SaveXmlDocument(doc, DbParamsFile); } }
public ParamInfo Clone() { ParamInfo info = new ParamInfo(); info.Key = Key; info.Value = Value; if (ItsNode == null) { info.ItsNode = null; } else { info.ItsNode = ItsNode.Clone(); } return info; }
public static ParamInfo LoadByXmlNode(XmlNode xmlNode) { ParamInfo item = new ParamInfo(); foreach (XmlNode child in xmlNode.ChildNodes) { switch (child.Name.ToUpper()) { case "KEY": item.Key = child.InnerText; break; case "VALUE": item.Value = child.InnerText; break; } } item.ItsNode = xmlNode; return item; }