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

C#中操作XML Node节点细节操作

文章来源:IT工程技术网 http://www.systhinker.com/html/43/n-11643.html
用的是一种很笨的方法,但可以帮助初学者了解访问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-


相关文档:

c#从html中获取图片地址

 
using System.Text.RegularExpressions;
string ohtml = this.TextBox1.Text;
            System.Text.RegularExpressions.MatchCollection m;
            //提取字符串的图片
   ......

c#:Dataset读取XML文件动态生成菜单

Step 1:Form1 上添加一个ToolStripContainer控件
Step2:实现代码
private void Form2_Load(object sender, EventArgs e)
{
    CMenuEx menu = new CMenuEx();
    string sPath = "D:\\Menu.xml";//xml的内容
     if (menu.FileExit())
  &nb ......

用VC++2005读XML文件的小例子

 1。写一个xml文件
 
 <?xml version="1.0" encoding="utf-8" ?>
- <root>
- <user id="101">
<name>abc</name>
<password>abc</password>
</user>
- <user id="102">
<name>ccc</name>
<password>ccc< ......

Xml字符串与C#对象之间相互转换

我们常常需要读取xml文件,把里面的信息转化为我们自定义的类型,或则吧自定义类型转化为Xml字符串。在这里介绍一个比较简单的对象转化方法。在我自己的Framwork里面也多次用到。里面涉及到节点、属性、集合。
示例一 该xml文件涉及到属性、节点集合不涉及个节点:
<?xml version="1.0" encoding="utf-8"?>
<da ......

C#中用于连接SQL数据库的SQLHelper类

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;   //引用命名空间
namespace DAL
{
    /*******************************************************************************
  &n ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号