资源简介
针对xml文件的对于节点的 增删改查操作实例。代码写的有点糙,见谅。

代码片段和文件信息
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;
//51aspx
public partial class Addxml : System.Web.UI.Page
{
protected void Page_Load(object sender EventArgs e)
{
}
protected void Button1_Click(object sender EventArgs e)
{
//操作四:添加一个节点
xmlDocument xmlDoc = new xmlDocument();
xmlDoc.Load(Server.MapPath(“xmlFile/xmlFile.xml“));
//创建一个新节点
xmlElement newElement = xmlDoc.CreateElement(“poems“);
//创建newElement下的节点
xmlElement elid = xmlDoc.CreateElement(“id“);
xmlElement elauthor = xmlDoc.CreateElement(“author“);
xmlElement eltitle = xmlDoc.CreateElement(“title“);
xmlElement elcontent = xmlDoc.CreateElement(“content“);
elid.InnerText = ReturnCount();
elauthor.InnerText = this.tbaddauthor.Text.Trim();
eltitle.InnerText = this.tbaddtitle.Text.Trim();
elcontent.InnerText = this.tbaddcontent.Text.Trim();
//将newElement下的节点加到newElement上
newElement.AppendChild(elid);
newElement.AppendChild(elauthor);
newElement.AppendChild(eltitle);
newElement.AppendChild(elcontent);
//将newElement加入到xml文件中(加在最后一条记录上)
xmlDoc.DocumentElement.AppendChild(newElement);
//如果要插到某条记录之后也可以用(加在第一条记录之后)
//xmlDoc.DocumentElement.InsertAfter(newElementxmlDoc.DocumentElement.ChildNodes.Item(0));
//如果要插到某条记录之前也可以用(加在第一条记录之前)
//xmlDoc.DocumentElement.InsertBefore(newElementxmlDoc.DocumentElement.ChildNodes.Item(0));
//存盘
xmlDoc.Save(Server.MapPath(“xmlFile/xmlFile.xml“));
Response.Redirect(“Default.aspx“);
}
public string ReturnCount()
{
//返回最后的ID值并+1
string i = string.Empty;
xmlDocument xmlDoc = new xmlDocument();
xmlDoc.Load(Server.MapPath(“xmlFile/xmlFile.xml“));
xmlNode xmlNode = xmlDoc.DocumentElement.LastChild;
if (xmlNode != null)
{
i = Convert.ToString(Convert.ToUInt32(xmlNode[“id“].InnerText) + 1);
}
return i;
}
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 879 2010-06-25 09:39 xm
文件 2032 2010-06-25 09:58 xm
文件 1695 2010-06-25 10:06 xm
文件 794 2010-06-25 10:33 xm
文件 434 2010-06-25 08:25 xm
文件 947 2010-06-25 10:15 xm
文件 692 2010-06-25 08:56 xm
文件 959 2010-06-25 09:12 xm
文件 876 2010-06-25 10:28 xm
文件 1800 2010-06-25 10:40 xm
文件 764 2010-06-25 11:40 xm
文件 417 2010-06-25 11:22 xm
文件 444 2010-06-25 11:18 xm
文件 409 2010-06-25 11:18 xm
文件 1642 2010-06-25 09:06 xm
文件 314 2010-06-25 11:19 xm
文件 747 2010-06-25 10:37 xm
文件 1650 2010-06-24 17:36 xm
文件 2576 2010-06-24 17:36 xm
文件 1236 2010-06-24 17:36 xm
文件 1881 2010-06-24 17:36 xm
文件 721 2010-06-25 06:58 xm
文件 459 2010-06-24 17:36 xm
文件 1259 2010-06-25 07:29 xm
文件 895 2010-06-24 17:36 xm
文件 2496 2010-06-25 07:35 xm
文件 725 2010-06-24 17:36 xm
文件 2622 2010-06-25 07:34 xm
文件 2638 2010-06-24 17:36 xm
文件 2887 2010-06-24 17:36 xm
............此处省略16个文件信息
- 上一篇:VTemplate及
- 下一篇:rtapi_w32.dll
相关资源
- J2EE 配置文件
-
开源tinyxm
l - 常用编码(UnicodeUTF-8GBK)转换工具
-
图片和xm
l格式互换 -
xm
l多个文件合并(delphi) -
xm
l课件及例题(xm l) -
《xm
l编程原理与实例教程》电子教 -
将数据库的表生成xm
l文件 -
简单的xm
l投票系统 -
notepad++包含xm
l tools等插件 -
Volley获取json和xm
l数据解析显示 -
李刚疯狂xm
l讲义第2版完整源码 -
maven settings.xm
l 直接使用 - Unity3D 实战视频教程 保卫萝卜 2D 游戏
-
Notepad++的xm
l格式化工具xm ltools_2 -
Notepad++的xm
l Tools插件格式化xm l文 -
map/list集合转化成xm
l字符串 xm l字 -
libxm
l2-2.9.4-rc2.tar.gz - antisamy策略文件
- 在线教学系统微信小程序
-
Tinyxm
l库文件 -
优秀xm
l程序设计(学生信息管理) - protobuf-2.4.1.zip
-
svnmaven xm
l Schema等程序员必备.7z -
xm
l基础教程-耿祥义 清华出版社 -
xm
l基础教程 第二版 PDF -
一个xm
l项目源代码 - 订单管理系统SSH框架
-
xm
l基础教程与实验指导课件PPT+源代 -
xm
l基础教程第2版教学课件
评论
共有 条评论