using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml;
namespace 上机题4
{
public partial class Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
XmlDocument xmlDoc = new XmlDocument();//创建DOM对象
xmlDoc.Load(Server.MapPath("News.xml"));//加载XML文档
XmlNode root = xmlDoc.SelectSingleNode("//News");//获取根节点
XmlElement xe1 = xmlDoc.CreateElement("New");//创建一个节点
XmlElement xesub1 = xmlDoc.CreateElement("Id");//创建子节点
xesub1.InnerText = "5";//设置子节点的数据
xe1.AppendChild(xesub1);//添加到节点中
XmlElement xesub2 = xmlDoc.CreateElement("Tilte");//创建子节点
xesub2.InnerText = "退房时间延长";//设置子节点的数据
xe1.AppendChild(xesub2);//添加到节点中
XmlElement xesub3 = xmlDoc.CreateElement("Content");//创建子节点
xesub3.InnerText = "从今天起退房时间可以延长到下午4点。";//设置子节点的数据
xe1.AppendChild(xesub3);//添加到节点中
XmlElement xesub4 = xmlDoc.CreateElement("Time");//创建子节点
xesub4.InnerText = "2012-10-16 10:38:00";//设置子节点的数据
xe1.AppendChild(xesub4);//添加到节点中
XmlElement xesub5 = xmlDoc.CreateElement("ImageUrl");//创建子节点
xesub5.InnerText = "4.jpg";//设置子节点的数据
xe1.AppendChild(xesub5);//添加到节点中
root.AppendChild(xe1);//添加到根节点中
xmlDoc.Save(Server.MapPath("News.xml"));//保存
Response.Write("<SCRIPT>alert('节点添加成功!')</SCRIPT>");
}
}
}