易截截图软件、单文件、免安装、纯绿色、仅160KB

C#里对xml文件进行修改,新增,删除,插入操作

已知有一个XML文件(bookstore.xml)如下:
<?xml version="1.0" encoding="gb2312"?>
<bookstore>
<book genre="fantasy" ISBN="2-3631-4">
<title>Oberon's Legacy</title>
<author>Corets, Eva</author>
<price>5.95</price>
</book>
</bookstore>
1、往<bookstore>节点中插入一个<book>节点:
XmlDocument xmlDoc=new XmlDocument();
xmlDoc.Load("bookstore.xml");
XmlNode root=xmlDoc.SelectSingleNode("bookstore");//查找<bookstore>
XmlElement xe1=xmlDoc.CreateElement("book");//创建一个<book>节点
xe1.SetAttribute("genre","李赞红");//设置该节点genre属性
xe1.SetAttribute("ISBN","2-3631-4");//设置该节点ISBN属性
XmlElement xesub1=xmlDoc.CreateElement("title");
xesub1.InnerText="CS从入门到精通";//设置文本节点
xe1.AppendChild(xesub1);//添加到<book>节点中
XmlElement xesub2=xmlDoc.CreateElement("author");
xesub2.InnerText="候捷";
xe1.AppendChild(xesub2);
XmlElement xesub3=xmlDoc.CreateElement("price");
xesub3.InnerText="58.3";
xe1.AppendChild(xesub3);
root.AppendChild(xe1);//添加到<bookstore>节点中
xmlDoc.Save("bookstore.xml");
//================
结果为:
<?xml version="1.0" encoding="gb2312"?>
<bookstore>
<book genre="fantasy" ISBN="2-3631-4">
<title>Oberon's Legacy</title>
<author>Corets, Eva</author>
<price>5.95</price>
</book>
<book genre="李赞红" ISBN="2-3631-4">
<title>CS从入门到精通</title>
<author>候捷</author>
<price>58.3</price>
</book>
</bookstore>
 
//2、修改节点:将genre属性值为“李赞红“的节点的genre值改为“update李//赞红”,将该节点的子节点<author>的文本修改为“亚胜”。
XmlNodeList nodeList=xmlDoc.SelectSingleNode("bookstore").ChildNodes;//获取bookstore节点的所有子节点
foreach(Xm


相关文档:

c# 读写XML文件

   用c#给PDA做了一个PC端的通讯程序,需要保存两个参数。用Delphi时,是保存在ini文件中,c#读写XML比较方便,就用xml文件来保存了。
   
 
class CXmlClass
{
private string XmlFilePath;
/// <summary>
/// 下载到PDA的TXT文件路径 
/// </summary>
......

使用JOX 进行JavaBean和XML的转换

今天试了个XML和JavaBean转换的软件JOX,之前一直有这样的需求,但比较来比较去还是这个比较简单实用。我想除非我有WS的需求,否则象JIBX和APACHE 的WS工具对我来说都是重量级的。
先看看输出结果:
<?xml version="1.0" encoding="ISO-8859-1"?>
<ApproxItem java-class="com.greatwall.csi.np.model.Approx ......

C# Xml中映射为类数据结构(报文)

        [System.Runtime.Serialization.DataMemberAttribute()]
        public Information Archive {
            get {
         &n ......

javascript操作xml生成树形菜单


这个效果应该不算什么稀奇,网上也有现成的代码,我这个也没什么特别的地方,只是因为我自己写的,也算是为学习DOM后一个练习;在IE下测试通过;
实现效果是这样的:
读取XML文档;
采用递归生成无限级的树形菜单;
能够响应鼠标事件,展开与拆叠子级菜单;
首先是生成一个XML文档,我用的是XML Spy的编辑器;
< ......

C#和JavaScript的简单互交

1.asp.net呼叫js
   
                     Response.Write("<script language=javascript>");
              &n ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号