日期:2014-05-18 浏览次数:20463 次
using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using System.Xml; using System.IO; public partial class manager_edit_news : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { string url = Server.MapPath("../../news.xml"); string news_id = Request.QueryString["news_id"]; XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(url); //加载XML文档 XmlNode root = xmlDoc.SelectSingleNode("news/content[news_id ='" + news_id + "']"); if (root != null) { Title.Text = root.ChildNodes[0].InnerText; Date.Text = DateTime.Now.ToString(); Description.Text = root.ChildNodes[2].InnerText; Content.Value = root.ChildNodes[3].InnerText; } } protected void btnSend_Click(object sender, EventArgs e) { string url = Server.MapPath("../../news.xml"); string news_id = Request.QueryString["news_id"]; string title = Request.Form["title"]; string description = Request.Form["description"]; string content = Request.Form["Content"]; //获取行信息的索引字段news_id XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(url); //加载XML文件 XmlNode root = xmlDoc.SelectSingleNode("news");//查找news节点 XmlNodeList xnl = root.ChildNodes; //获取news下面所以子节点 for (int i = 0; i < xnl.Count; i++) { XmlNodeList xnl11 = xnl.Item(i).SelectNodes("news_id");//查找news_id下面节点集合 XmlElement xe = (XmlElement)xnl11.Item(0); //news_id节点下面的元素 if (xe.InnerText == news_id) //获取节点以及所有子集的串联值 { xe.InnerText = news_id; xe.ParentNode.ChildNodes.Item(0).InnerText = title; xe.ParentNode.ChildNodes.Item(1).InnerText = DateTime.Now.ToString(); xe.ParentNode.ChildNodes.Item(2).InnerText = description; [color=#FF0000]xe.ParentNode.ChildNodes.Item(3).InnerText = content;[/color] } } xmlDoc.Save(url); Response.Redirect("manager.aspx"); } }
<news originalMenuTitleColor="0xCCCC33" originalMenuDateColor="0x666666" currentMenuTitleColor="0x00CCFF" currentMenuDateColor="0xCCCCCC" arrowOutColor="0x999999" arrowOverColor="0xCCCC33" mainTitleColor="0xCCCC33" menuSpacing="40" textHolderXStart="220" textHolderXFinish="240" mainTextWidth="600" scrollbarX="855"> <content> <title>测试文章</title> <date>2008-12-22 12:27:37</date> <description>测试文章简介</description> <main>&lt;p&gt;111&lt;/p&gt;</main> <news_id>1</news_id> </content>