title: C# : Modify a xml node
body: <p>i have that xml file :</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;reminders&gt;
    &lt;reminder&gt;
      &lt;Title&gt;Alarm1&lt;/Title&gt;
      &lt;Description&gt;Desc1&lt;/Description&gt;
      &lt;Time&gt;03/07/2012 10:11AM&lt;/Time&gt;
      &lt;snooze&gt;1&lt;/snooze&gt;
      &lt;repeat&gt;None&lt;/repeat&gt;
    &lt;/reminder&gt;
  &lt;/reminders&gt;
  </code></pre>
  
  <p>And i want to modify the  innertext from Alarm1 to another value so i wrote that code which actually duplicate the entire node .</p>
  
  <pre><code>        XmlDocument xml = new XmlDocument();
  
          xml.Load("0.xml");
  
          XmlNodeList elements = xml.SelectNodes("//reminders");
  
          foreach (XmlNode element in elements)
          {
              if (element.InnerText == "Alarm1")
              {
                  XmlNode newvalue = xml.CreateElement("MODIFIED");
                  element.ReplaceChild(newvalue, element);
  
                  xml.Save("0.xml");
              }
          }
  </code></pre>
  
  <p>And then tried another code :</p>
  
  <pre><code>        foreach (XmlElement element in xml.SelectNodes("//reminder"))
          {
              if (element.InnerText == "Alarm1")
              {
                  XmlNode newvalue = xml.CreateElement("MODIFIED");
                  element.ReplaceChild(newvalue, element);
  
                  xml.Save("0.xml");
              }
          }
  </code></pre>
  
  <p>But also doesn`t work....</p>
  
  <p>EDIT 1 : [Figured out a new code]</p>
  
  <pre><code>        XmlDocument xml = new XmlDocument();
  
          xml.Load("0.xml");
  
          foreach (XmlElement element in xml.SelectNodes("//reminder"))
          {
              foreach (XmlElement element1 in element)
              {
                  if (element.SelectSingleNode("//Title").InnerText == "Alarm1")
                  {
                      XmlNode newvalue = xml.CreateElement("MODIFIED");
                      element.ReplaceChild(newvalue, element1);
  
                      xml.Save("0.xml");
                  }
              }
          }
  </code></pre>
  
  <p>But it made the Alarm1 becomes</p>
  
  <pre><code>&lt;MODIFIED /&gt;
  </code></pre>
  
  <p>EDIT 2 : [I SOLVED IT :D]
  Okay here is the code i could figure out :</p>
  
  <pre><code>        XmlDocument xml = new XmlDocument();
  
          xml.Load("0.xml");
  
          foreach (XmlElement element in xml.SelectNodes("//reminder"))
          {
              foreach (XmlElement element1 in element)
              {
                  if (element.SelectSingleNode("//Title").InnerText == "Alarm1")
                  {
                      MessageBox.Show(element1.InnerText);
                      XmlNode newvalue = xml.CreateElement("Title");
                      newvalue.InnerText = "MODIFIED";
                      element.ReplaceChild(newvalue, element1);
  
                      xml.Save("0.xml");
                  }
              }
          }
  </code></pre>
  
  <p>I`ll really appreciate your helps and thanks.</p>