title: How to Delete XML Node?
body: <p>I have created methods for selecting and removing nodes from XML. My code runs but XML node is not removed. </p>
  
  <p>I do not know where the code is wrong please help me for this problem:</p>
  
  <pre><code>public XmlNodeList getXmlNodeList(string XmlNodeName)
  {
      XmlDocument doc = new XmlDocument();
      doc.Load(_connection);
      XmlNodeList elemList = doc.GetElementsByTagName(XmlNodeName);
      return elemList;
  }
  
  public void deleteXmlNode(string XmlNodeName, string XmlNodeValue)
  {
      XmlDocument xdoc = new XmlDocument();
      xdoc.Load(_connection);
      XmlNodeList xnode = getXmlNodeList(XmlNodeName);
  
      foreach (XmlNode item in xnode)
      {
          if (item.InnerText == XmlNodeValue)
          {
              item.ParentNode.RemoveChild(item);
              break;
          }
      }
      xdoc.Save(_connection);
  }
  </code></pre>
  
  <p>My XML code:</p>
  
  <pre><code>&lt;AriaGostarInformation&gt;
    &lt;MenuInformation&gt;
      &lt;MenuNames&gt;
        one
      &lt;/MenuNames&gt;
      &lt;MenuNames Name="1"&gt;two&lt;/MenuNames&gt;
      &lt;MenuNames Name="2"&gt;three&lt;/MenuNames&gt;
      &lt;MenuNames Name="3"&gt;four&lt;/MenuNames&gt;
      &lt;MenuNames Name="4"&gt;five&lt;/MenuNames&gt;
      &lt;MenuNames Name="5"&gt;six&lt;/MenuNames&gt;
      &lt;SubMenuNames parentName="1"&gt;
        fgfgfgfgs
      &lt;/SubMenuNames&gt;
      &lt;SubMenuNames parentName="3"&gt;
      &lt;/SubMenuNames&gt;
    &lt;/MenuInformation&gt;
    &lt;SliderInformation&gt;
    &lt;/SliderInformation&gt;
    &lt;LasProductInformation&gt;
      &lt;Product&gt;
        &lt;ImageAddress alt=""&gt;../Static/Css/Images/c.jpg&lt;/ImageAddress&gt;
        &lt;Subject&gt;bere&lt;/Subject&gt;
        &lt;Description&gt;nare&lt;/Description&gt;
      &lt;/Product&gt;
      &lt;Product&gt;
        &lt;ImageAddress alt=""&gt;../Static/Css/Images/c.jpg&lt;/ImageAddress&gt;
        &lt;Subject&gt;bere&lt;/Subject&gt;
        &lt;Description&gt;nare&lt;/Description&gt;
      &lt;/Product&gt;
      &lt;Product&gt;
        &lt;ImageAddress alt=""&gt;../Static/Css/Images/c.jpg&lt;/ImageAddress&gt;
        &lt;Subject&gt;bere&lt;/Subject&gt;
        &lt;Description&gt;nare&lt;/Description&gt;
      &lt;/Product&gt;
      &lt;Product&gt;
        &lt;ImageAddress alt=""&gt;../Static/Css/Images/c.jpg&lt;/ImageAddress&gt;
        &lt;Subject&gt;bere&lt;/Subject&gt;
        &lt;Description&gt;nare&lt;/Description&gt;
      &lt;/Product&gt;
      &lt;Product&gt;
        &lt;ImageAddress alt=""&gt;../Static/Css/Images/c.jpg&lt;/ImageAddress&gt;
        &lt;Subject&gt;bere&lt;/Subject&gt;
        &lt;Description&gt;nare&lt;/Description&gt;
      &lt;/Product&gt;
      &lt;Product&gt;
        &lt;ImageAddress alt=""&gt;../Static/Css/Images/c.jpg&lt;/ImageAddress&gt;
        &lt;Subject&gt;bere&lt;/Subject&gt;
        &lt;Description&gt;nare&lt;/Description&gt;
      &lt;/Product&gt;
      &lt;Product&gt;
        &lt;ImageAddress alt=""&gt;../Static/Css/Images/c.jpg&lt;/ImageAddress&gt;
        &lt;Subject&gt;bere&lt;/Subject&gt;
        &lt;Description&gt;nare&lt;/Description&gt;
      &lt;/Product&gt;
      &lt;Product&gt;
        &lt;ImageAddress alt=""&gt;../Static/Css/Images/c.jpg&lt;/ImageAddress&gt;
        &lt;Subject&gt;bere&lt;/Subject&gt;
        &lt;Description&gt;nare&lt;/Description&gt;
      &lt;/Product&gt;
      &lt;Product&gt;
        &lt;ImageAddress alt=""&gt;../Static/Css/Images/c.jpg&lt;/ImageAddress&gt;
        &lt;Subject&gt;bere&lt;/Subject&gt;
        &lt;Description&gt;nare&lt;/Description&gt;
      &lt;/Product&gt;
      &lt;Product&gt;
        &lt;ImageAddress alt=""&gt;../Static/Css/Images/c.jpg&lt;/ImageAddress&gt;
        &lt;Subject&gt;bere&lt;/Subject&gt;
        &lt;Description&gt;nare&lt;/Description&gt;
      &lt;/Product&gt;
      &lt;Product&gt;
        &lt;ImageAddress alt=""&gt;../Static/Css/Images/c.jpg&lt;/ImageAddress&gt;
        &lt;Subject&gt;bere&lt;/Subject&gt;
        &lt;Description&gt;nare&lt;/Description&gt;
      &lt;/Product&gt;
      &lt;Product&gt;
        &lt;ImageAddress alt=""&gt;../Static/Css/Images/c.jpg&lt;/ImageAddress&gt;
        &lt;Subject&gt;bere&lt;/Subject&gt;
        &lt;Description&gt;nare&lt;/Description&gt;
      &lt;/Product&gt;
      &lt;Product&gt;
        &lt;ImageAddress alt=""&gt;../Static/Css/Images/c.jpg&lt;/ImageAddress&gt;
        &lt;Subject&gt;bere&lt;/Subject&gt;
        &lt;Description&gt;nare&lt;/Description&gt;
      &lt;/Product&gt;
      &lt;Product&gt;
        &lt;ImageAddress alt=""&gt;../Static/Css/Images/c.jpg&lt;/ImageAddress&gt;
        &lt;Subject&gt;bere&lt;/Subject&gt;
        &lt;Description&gt;nare&lt;/Description&gt;
      &lt;/Product&gt;
      &lt;Product&gt;
        &lt;ImageAddress alt=""&gt;../Static/Css/Images/c.jpg&lt;/ImageAddress&gt;
        &lt;Subject&gt;bere&lt;/Subject&gt;
        &lt;Description&gt;nare&lt;/Description&gt;
      &lt;/Product&gt;
    &lt;/LasProductInformation&gt;
  &lt;/AriaGostarInformation&gt;
  </code></pre>