public static XmlOprResult SafeLoad(this XmlDocument xmlDoc, string xmlFile) { XmlOprResult result = XmlOprResult.OK; try { xmlDoc.Load(xmlFile); } catch { result = XmlOprResult.FailedLoad; } return(result); }
public static XmlOprResult Delete(this XmlDocument xmlDoc, string xmlFile, string xpath) { XmlOprResult result = XmlOprResult.OK; XmlNode node = xmlDoc.SelectSingleNode(xpath); if (node != null) { node.RemoveAll(); xmlDoc.Save(xmlFile); } else { result = XmlOprResult.NonExistence; } return(result); }
public static XmlOprResult UpdateInnerText(this XmlDocument xmlDoc, string xmlFile, string parentPath, string value) { XmlOprResult result = XmlOprResult.OK; XmlNode node = xmlDoc.SelectSingleNode(parentPath); if (node != null) { node.InnerText = value; xmlDoc.Save(xmlFile); } else //Have't found { result = XmlOprResult.NonExistence; } return(result); }
public static XmlOprResult AddUniqueNode(this XmlDocument xmlDoc, string xmlFile, string parentPath, string name) { XmlOprResult result = XmlOprResult.OK; if (!Exists(xmlDoc, parentPath + "/" + name)) { XmlNode node = xmlDoc.SelectSingleNode(parentPath); XmlElement element = xmlDoc.CreateElement(name); node.AppendChild(element); xmlDoc.Save(xmlFile); } else { result = XmlOprResult.Repeated; } return(result); }
public static XmlOprResult AddNode(this XmlDocument xmlDoc, string xmlFile, string parentPath, string name, string innerText) { XmlOprResult result = XmlOprResult.OK; if (Exists(xmlDoc, parentPath)) { XmlNode node = xmlDoc.SelectSingleNode(parentPath); XmlElement element = xmlDoc.CreateElement(name); element.InnerText = innerText; node.AppendChild(element); xmlDoc.Save(xmlFile); } else { result = XmlOprResult.NonExistence; } return(result); }
public static XmlOprResult AddItem(this XmlDocument xmlDoc, string xmlFile, string parentPath, string name, string value) { XmlOprResult result = XmlOprResult.OK; XmlNode node = xmlDoc.SelectSingleNode(parentPath); if (node != null) { XmlElement element = xmlDoc.CreateElement(name); XmlText text = xmlDoc.CreateTextNode(value); element.AppendChild(text); node.AppendChild(element); xmlDoc.Save(xmlFile); } else { result = XmlOprResult.NonExistence; } return(result); }