我想做的是当我在 xmlTitle.Text(textbox) 和 xmlContent.Text(textbox) 上放一些东西时,我希望我的 TextXML.xml 将被更新,请帮忙吗?
protected void Button1_Click(object sender, EventArgs e)
{
XmlDocument xmlfile = new XmlDocument();
xmlfile.Load(Server.MapPath ("~/TestXML.xml"));
//create element
XmlElement theNewsTag = xmlfile.CreateElement("news");
XmlElement theTitleTag = xmlfile.CreateElement("title");
XmlElement theContentsTag = xmlfile.CreateElement("contents");
//create text node
XmlText theTitleText = xmlfile.CreateTextNode(xmlTitle.Text);
XmlText theContentsText = xmlfile.CreateTextNode(xmlContent.Text);
//append
theTitleTag.AppendChild(theTitleText);
theContentsTag.AppendChild(theContentsText);
theNewsTag.AppendChild(theTitleTag);
theNewsTag.AppendChild(theContentsTag);
//save
xmlfile.DocumentElement.AppendChild(theNewsTag);
xmlfile.Save(Server.MapPath ("~/TestXML.xml"));
}