Remove Element from XmlElement - CSharp System.Xml

CSharp examples for System.Xml:XML Element

Description

Remove Element from XmlElement

Demo Code

//              Copyright (c) 2006-2017 All Rights reserved                   *
using System.Xml.XPath;
using System.Xml;
using System.IO;/* w ww  .  ja v  a 2 s  . c om*/
using System.Globalization;
using System;

public class Main{
        public static void RemoveElement(XmlElement element)
      {
         var parentNode = element.ParentNode;
         parentNode.RemoveChild(element);
      }
        #endregion

      #region RemoveElement

      public static void RemoveElement(XmlDocument document, string XPath)
      {
         XmlNode parentNode = null;
         XmlNodeList nodes = null;

         nodes = document.SelectNodes(XPath);
         foreach (XmlElement node in nodes)
         {
            parentNode = node.ParentNode;
            node.RemoveAll();
            parentNode.RemoveChild(node);
         }
      }
}

Related Tutorials