发文章
发文工具
撰写
网文摘手
文档
视频
思维导图
随笔
相册
原创同步助手
其他工具
图片转文字
文件清理
AI助手
留言交流
C#—XML读取、增加、修改和删除操作 1.xml文件格式如下:<?xml version="1.0" encoding="utf-8"?><projects><project name="PlatformFramewo" vss-path="Platform$/Source CodHdt$Pla~1.sln" /></projects>
1.读取DataSet ds = new DataSet();ds.ReadXml(Server.MapPath(@"Projects.xml"));DataTable dt = ds.Tables[0];return dt;//得到的datable在前台进行循环输出,省略...<tr style="font-weight: bold;"> //文字加粗<td style="border-bottom: solid 2px gray;"> //文字底部加横线
2.新增XmlDocument xmlDoc = new XmlDocument();string Path = Server.MapPath(@"Projects.xml");xmlDoc.Load(Path);XmlNode root=xmlDoc.SelectSingleNode("projects");XmlElement xe1 = xmlDoc.CreateElement("project");xe1.SetAttribute("name", txtProjectName.Text);strVssPath = txtProjectVss.Text + "$" + txtProjectPath.Text + "$" + txtProjectSln.Text;xe1.SetAttribute("vss-path",strVssPath);root.AppendChild(xe1);xmlDoc.Save(Path);
3.修改XmlDocument xmlDoc = new XmlDocument();string Path = Server.MapPath(@"Projects.xml");xmlDoc.Load(Path);XmlNodeList nodelist = xmlDoc.SelectSingleNode("projects").ChildNodes;foreach (XmlNode xn in nodelist){ XmlElement xe = (XmlElement)xn; if (xe.GetAttribute("name") == Request["name"].ToString()) { xe.SetAttribute("name", txtProjectName1.Text); strVssPath = txtProjectVss1.Text + "$" + txtProjectPath1.Text + "$" + txtProjectSln1.Text; xe.SetAttribute("vss-path", strVssPath); xmlDoc.Save(Path); } }
4.删除XmlDocument xmlDoc = new XmlDocument();string Path = Server.MapPath(@"Projects.xml");xmlDoc.Load(Path);XmlNodeList nodelist = xmlDoc.SelectSingleNode("projects").ChildNodes;foreach (XmlNode xn in nodelist){ XmlElement xe = (XmlElement)xn; if (xe.GetAttribute("name") == Request["name"].ToString()) { xn.ParentNode.RemoveChild(xn); xmlDoc.Save(Path); }}
来自: 昵称10504424 > 《Asp.Net》
0条评论
发表
请遵守用户 评论公约
C#:XML操作类
怎样在C#里对xml文件进行修改,新增,删除,插入操作?
InnerText="CS从入门到精通";//设置文本节点xe1.AppendChild(xesub1);//添加到<book>节点中XmlElement xesub2=xmlDoc.CreateElement("author");xesub2.InnerText="候捷...
VB.NET中操作xml文件
GetAttribute("genre")) ''显示属性值 Console.WriteLine(xe.GetAttribute("ISBN"))Dim xnf1 As XmlNodeList = xe.ChildNodesDim xn2 As XmlNodeFor Each xn2 In xnf1Cons...
C#读写xml文件(2)
C#读写xml文件(2)C#读写xml文件作者: nileel 来源: CSDN 发布时间: 2008-09-09 19:13 阅读: 62487 次 推荐: 17 原文链接 [收藏] [1] C#读写xml文件[2] C#读写xml文件3、删除 <book genre=...
使用XML文件保存应用程序配置
一种使用XML保存应用程序配置的方法,取代*.ini和Registry
unity3d学习笔记(十六)unity3d读取plist或xml文件
unity3d学习笔记(十六)unity3d读取plist或xml文件。这里说到配置文件,花样就多了,以前做cocos2d-x游戏时,用的最多的是plist文件和c...
ASP.NET C# 操作 Excel
ASP.NET C# 操作 ExcelASP.NET C# 操作 Excel 从Excel读取数据。今天,从MSDN网上找到一篇从EXCEL读取数据到DATAGRID的文章(详见http://support.microsoft.com/kb/306572/zh-cn),但是,这种方法有局限...
c#写XML
InnerText="CS从入门到精通";//设置文本节点 xe1.AppendChild(xesub1);//添加到<Node>节点中 XmlElement xesub2=xmldoc.CreateElement("author"); xesub2.InnerText="...
盒子论坛 v2.1
关于 服务端与大量客户端 wcf + Delphi or asp.net还是datasnap + delphi and asp.net.这两个月想重新写几个程序,统一的由网上的服务器提供数据服务,开始我先优考虑用C#写个WCF服务端,用Asp.net做客...
微信扫码,在手机上查看选中内容