首页 > 代码库 > 修改XML的节点内容

修改XML的节点内容

这种形式可以修改任何一个节点:

  XmlDocument doc = new XmlDocument();  doc.Load("Event.xml");  XmlElement events = doc.DocumentElement;  XmlNode xn = events;  foreach (XmlNode node in xn.ChildNodes)  {    if (node["事件名"].InnerText == textBox1.Text)    {      XmlNode xnStartTime = node["开始时间"];      xnStartTime[""].InnerText = comboBox1.SelectedItem.ToString();      xnStartTime[""].InnerText = comboBox2.SelectedItem.ToString();      XmlNode xnEndTime = node["终止时间"];      xnEndTime[""].InnerText = comboBox4.SelectedItem.ToString();      xnEndTime[""].InnerText = comboBox3.SelectedItem.ToString();      int height = ((Convert.ToInt32(comboBox4.Text) - Convert.ToInt32(comboBox1.Text)) * 6 + (Convert.ToInt32(comboBox3.Text) / 10 - Convert.ToInt32(comboBox2.Text) / 10))*9;
      node[
"高度"].InnerText = Convert.ToString(height);      if (radioButton1.Checked == true)      {        node["重要"].InnerText = "";      }      else      {        node["重要"].InnerText = "";      }      if (radioButton4.Checked == true)      {        node["紧迫"].InnerText = "";      }      else      {        node["紧迫"].InnerText = "";      }    }  }  doc.Save("Event.xml");

 

修改XML的节点内容