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");
            int maxId=Convert.ToInt32(doc.Root.Attribute("maxId").Value)+1;
            doc.Root.Attribute("maxId").Value = maxId.ToString();
            XElement article=new XElement("Article",
                new XElement("ID",maxId.ToString()),
                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);
            doc.Save("Datasource.xml");
            Response.Redirect("Default.aspx");
        }
    }
}
