public void PasteNode(string xpath, System.Xml.XmlNode oXmlNode) { System.Xml.XmlElement Parent = (System.Xml.XmlElement)XmlDocument.SelectSingleNode(xpath); if (Parent.NodeType != System.Xml.XmlNodeType.Element) { throw new Exception("selected node can't received this stick node"); } else { if (oXmlNode.NodeType == System.Xml.XmlNodeType.Element) { System.Xml.XmlElement oXmlElement = (System.Xml.XmlElement)oXmlNode.Clone(); if (ContainsElement(Parent, oXmlElement)) { throw new Exception("Element already exist"); } else if (Parent.ChildNodes.Count == 1 && Parent.FirstChild.NodeType == System.Xml.XmlNodeType.Text) { throw new Exception("Element has text"); } else { Parent.AppendChild(oXmlElement); } } if (oXmlNode.NodeType == System.Xml.XmlNodeType.Attribute) { System.Xml.XmlAttribute oXmlAttribute = (System.Xml.XmlAttribute)oXmlNode.Clone(); if (ContainsAttribute(oXmlAttribute, Parent)) { throw new Exception("Attribute already exist"); } else { Parent.Attributes.Append(oXmlAttribute); } } } }
public System.Xml.XmlNode CutNode(string xpath) { System.Xml.XmlNode oXmlNode = XmlDocument.SelectSingleNode(xpath); System.Xml.XmlNode oXmlNodeCut = oXmlNode.Clone(); if (oXmlNode.ParentNode == null) { XmlDocument.RemoveChild(oXmlNode); } else { oXmlNode.ParentNode.RemoveChild(oXmlNode); } return(oXmlNodeCut); }