using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml.Linq;

namespace BookDemo.RSS
{
    public partial class ArticleAdd : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

protected void Button1_Click(object sender, EventArgs e)
{
    XDocument doc = XDocument.Load("Datasource.xml");//载入XML数据源
    int maxId=Convert.ToInt32(doc.Root.Attribute("maxId").Value);//获取当前最大ID
    maxId++;//最大ID加1
    doc.Root.Attribute("maxId").Value = maxId.ToString();//设置数据源的新的最大ID
    XElement article = new XElement("Article",//Article节点
        new XElement("ID",maxId.ToString()),//最大ID
        new XElement("Title",txtTitle.Text.Trim()),//标题
        new XElement("Description", new XCData(txtDescription.Text.Trim().Replace("\r\n", "<br />"))),//描述
        new XElement("Text",new XCData(txtText.Text.Trim().Replace("\r\n","<br />"))),//正文
        new XElement("CreateTime",DateTime.Now.ToString())//创建时间
        );
    doc.Root.Add(article);//将Article节点追加到根节点的下级节点中
    doc.Save("Datasource.xml");//保存Datasource.xml
    Response.Redirect("Default.aspx");//返回首页（列表页面）
}
    }
}
