易截截图软件、单文件、免安装、纯绿色、仅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#: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 ......

XML和HTML常用转义字符

XML和HTML常用转义字符
XML和HTML中都有一些特殊的字符,这些字符在XML和HTML中是不能直接使用的,如果必须使用这些字符,应该使用其对应的转义字符。

 
如果在XML文档中使用类似"<" 的字符, 那么解析器将会出现错误,因为解析器会认为这是一个新元素的开始。
所以不应该像下面那样书写代码:
<message&g ......

C# 用SQL新建数据库

1. 程序如下:
         string str = "Create Database " + "DBname";
         string con = "Data Source=10.0.0.249\\sql2005;Initial Catalog=master;Persist Security Info=True;User ID=sa;Password=sa";
   &n ......

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 ......

java中的super与c#中的base


C#中对base的解释(引自MSDN):
base 关键字用于从派生类中访问基类的成员:
调用基类上已被其他方法重写的方法。
指定创建派生类实例时应调用的基类构造函数。
基类访问只能在构造函数、实例方法或实例属性访问器中进行。
从静态方法中使用 base 关键字是错误的。
在本例中,基类 Person 和派生类 Employee 都有一个 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号