动态往xml中添加数据
来源:互联网 发布:淘宝标题优化技巧视频 编辑:程序博客网 时间:2024/05/17 08:06
类:
using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Xml;/// <summary>///Class1 的摘要说明/// </summary>public class Class1{ private XmlDocument xmlDoc; private string author; private string publisher; private string date; private string name; private string isbn; private string price;public Class1(){////TODO: 在此处添加构造函数逻辑//} public Class1(string au, string pu, string date, string na, string isbn,string price) { this.author = au; this.publisher = pu; this.date = date; this.name = na; this.isbn = isbn; this.price = price; } /// <summary> /// 加载XML文件的方法 /// </summary> /// <param name="xmlfile">XML文件路径</param> private void LoadXml() { xmlDoc = new XmlDocument(); xmlDoc.Load(System.Web.HttpContext.Current.Server.MapPath("books.xml")); } public void AddNode() { //加载文档 LoadXml(); //选择根节点 XmlNode xmldocboot = xmlDoc.SelectSingleNode("books"); //开始添加节点及节点的属性 XmlElement ele = xmlDoc.CreateElement("book"); XmlElement ele1 = xmlDoc.CreateElement("author"); ele1.InnerText = author; XmlElement ele2 = xmlDoc.CreateElement("publisher"); ele2.InnerText = publisher; XmlElement ele3 = xmlDoc.CreateElement("date"); ele3.InnerText = date; XmlElement ele4 = xmlDoc.CreateElement("name"); ele4.InnerText = name; XmlElement ele5 = xmlDoc.CreateElement("isbn"); ele5.InnerText = isbn; XmlElement ele6 = xmlDoc.CreateElement("price"); ele6.InnerText = price; ele.AppendChild(ele1); ele.AppendChild(ele2); ele.AppendChild(ele3); ele.AppendChild(ele4); ele.AppendChild(ele5); ele.AppendChild(ele6); //将节点保存到根节点下 xmldocboot.AppendChild(ele); //保存XML文件的修改-此处要注意 xmlDoc.Save(System.Web.HttpContext.Current.Server.MapPath("books.xml")); }}
后台调用:
Class1 myxml = new Class1(this .txt_author .Text ,this .txt_pub .Text ,this .txt_date .Text ,this .txt_bookname .Text ,this .txt_isbn .Text ,this .txt_price .Text ); //执行添加命令 myxml.AddNode();
- 动态往xml中添加数据
- PHP动态添加XML中的数据
- flex中给xml动态添加
- xml数据岛中添加记录
- 动态的向ListView中添加数据
- Ext 中树的动态添加数据
- [PHP]向类中动态添加数据
- C#中DataGrid加载XML数据--添加数据
- XML数据岛中数据的编辑和添加
- 动态添加数据
- datagridview 数据动态添加
- ListView动态添加数据
- highchart 动态添加数据
- DataGridView动态添加数据
- 动态添加数据(一)
- 动态添加数据(二)
- 动态添加数据(三)
- 动态添加数据
- 用log parser 2.2将IIS log 转换成Access或者Excel
- Android之PreferenceActivity
- winform打包发布安装包
- 重载赋值运算符
- DreamWeaverCS5+JQuery写的简单的导航栏
- 动态往xml中添加数据
- C语言 遍历文件夹查找最后创建的文件
- 函数指针温故
- Flex中Number类型的格式化小数位
- 在重写Gallery之后 解决重写Adapter内加载Layout过小的问题
- MAP getLastKnownLocation()返回null的解决
- 关于斜率优化的DP
- OpenGL ES的1.0
- How to adb connection with Kindle Fire