C#使用XML
用的是一种很笨的方法,但可以帮助初学者了解访问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>
相关文档:
using System;
using System.Data;
using System.Data.OleDb;
namespace AccessDb
{
/**//// <summary>
/// AccessDb 的摘要说明,以下信息请完整保留
/// 请在数据传递完毕后调用Close()方法,关闭数据链接。
/// </summary>
public class AccessDbClass
{
变量声 ......
1 前言
如果你熟悉Microsoft Foundation Classes(MFC)的CString,Windows Template
Library(WTL)的CString或者Standard Template
Library(STL)的字符串类,那么你对String.Format方法肯定很熟悉。在C#中也经常使用这个方法来格式化字符串,比如下面这样:
int x = 16;
decimal y = 3.57m ......
C# Java命名规则
C# (C#高级编程,微软设计模式)
命名空间,类,方法 :每个单词的第一个字母大写 例 ServerCode。
(采用Pascal大小写规则)
私有成员:单词的第一个字母小写,通常前面加上“_” 例 _name 或 _serverCode。
(采用camell大小写规则)
Java (java设计 ......
因为项目要求,制作的一个多文件上传,并显示进度条一段代码(vs2005环境)。
(只为粗略的实现,代码并不规范)
当多个文件上传的时候,需要依次队列形式一个个上传,当上传某个文件的时候,锁定进程,上传完毕再开启锁。
在主类中的上传按钮事件代码:
//
获取openFileDialog控件选择的文件名数组(openFileDialog可 ......
using System.Security.Cryptography;
using System.IO;
using System.text;
/// <summary>
/// 加密
/// </summary>
/// <param name="str"> ......