public void ReplaceNode(string xpathToReplacedNode, string xmlContentOfNewNode) { if (string.IsNullOrEmpty(xmlContentOfNewNode) || string.IsNullOrEmpty(xmlContentOfNewNode)) { return; } XmlNode oldNode = WITD.SelectSingleNode(xpathToReplacedNode); if (null == oldNode) { return; } XmlNode parentNode = oldNode.ParentNode; parentNode.RemoveChild(oldNode); XmlNode newControlNode = ImportNode(WITD, xmlContentOfNewNode); parentNode.AppendChild(newControlNode); TraceManager.TraceInformation("Replacing the node: {0} with {1}", xpathToReplacedNode, newControlNode.OuterXml); }
public void InsertNode(string xpathToParentNode, string nodeContent, string xpathToCheckDuplicate) { if (string.IsNullOrEmpty(nodeContent) || string.IsNullOrEmpty(xpathToParentNode)) { return; } if (!string.IsNullOrEmpty(xpathToCheckDuplicate)) { XmlNode customField = WITD.SelectSingleNode(xpathToCheckDuplicate); if (null != customField) { return; } } XmlNode fieldsNode = WITD.SelectSingleNode(xpathToParentNode); Debug.Assert(fieldsNode != null); XmlNode fieldNode = ImportNode(WITD, nodeContent); fieldsNode.AppendChild(fieldNode); TraceManager.TraceInformation("Inserting the node: {0}", fieldNode.OuterXml); }
public void DeleteNode(string xpathToRemovingNode) { if (string.IsNullOrEmpty(xpathToRemovingNode)) { return; } XmlNodeList nodesToRemove = WITD.SelectNodes(xpathToRemovingNode); if (nodesToRemove == null) { return; } foreach (XmlNode node in nodesToRemove) { TraceManager.TraceInformation("Removing the node: {0}", node.OuterXml); XmlNode parent = node.ParentNode; parent.RemoveChild(node); } }
public void AddAttribute(string xpathToNode, string newAttribute, string attributeValue) { if (string.IsNullOrEmpty(xpathToNode) || string.IsNullOrEmpty(newAttribute) || string.IsNullOrEmpty(attributeValue)) { return; } XmlNode oldNode = WITD.SelectSingleNode(xpathToNode); if (null == oldNode) { return; } XmlAttribute attribute = WITD.CreateAttribute(newAttribute); attribute.Value = attributeValue; oldNode.Attributes.Append(attribute); TraceManager.TraceInformation("Adding attribute to the node: Adding {0} = {1} to {2}", newAttribute, attributeValue, xpathToNode); }