使用XmlDocument类完成对XML的查、删、添、改
使用XmlDocument类完成对XML的查、删、添、改
http://www.aspdiy.net/article/53.htm
后台C#代码
1using System;
2using System.Collections;
3using System.ComponentModel;
4using System.Data;
5using System.Drawing;
6using System.Web;
7using System.Web.SessionState;
8using System.Web.UI;
9using System.Web.UI.WebControls;
10using System.Web.UI.HtmlControls;
11//新引入两个命名空间
12using System.Xml;
13using System.Xml.XPath;
14
15namespace XML
16{
17 /**//// <summary>
18 /// xdoc 的摘要说明。
19 /// </summary>
20 public class xdoc : System.Web.UI.Page
21 {
22 protected System.Web.UI.WebControls.Label Label1;
23 protected System.Web.UI.WebControls.Label Label2;
24 protected System.Web.UI.WebControls.Button Button1;
25 protected System.Web.UI.WebControls.Label Label3;
26 protected System.Web.UI.WebControls.Button Button2;
27 protected System.Web.UI.WebControls.Button Button3;
28 protected System.Web.UI.WebControls.DataGrid dg;
29 protected System.Web.UI.WebControls.DropDownList ddl;
30 protected System.Web.UI.WebControls.TextBox tbn;
31 protected System.Web.UI.WebControls.Label Label4;
32 protected System.Web.UI.WebControls.Label Label5;
33 protected System.Web
相关文档:
我们常常需要读取xml文件,把里面的信息转化为我们自定义的类型,或则吧自定义类型转化为Xml字符串。在这里介绍一个比较简单的对象转化方法。在我自己的Framwork里面也多次用到。里面涉及到节点、属性、集合。
示例一 该xml文件涉及到属性、节点集合不涉及个节点:
<?xml version="1.0" encoding="utf-8"?>
<da ......
Product.xml
<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/css" href="product.css" ?>
<productata>
<product prodid="p001" category="toy">
<productname>Mini Bus</productname>
<description>This is a toy for childern aged 4 and above&l ......
Class.xml
<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/css" href="class.css"?>
<bookdetail>
<book class="A">
<author>曹雪芹</author>
<title>红楼梦</title>
<price>60.00</price>
</book>
<book class="A"& ......
一、简单介绍
using System.Xml;
//初始化一个xml实例
XmlDocument xml=new XmlDocument();
//导入指定xml文件
xml.Load(path);
xml.Load(HttpContext.Current.Server.MapPath("~/file/bookstore.xml"));
//指定一个节点
XmlNode root=xml.SelectSingleNode("/root");
//获取节点下所有直接子节点
XmlNodeList ......
Xml文件操作和文件操作(FileInfo类)
1. 上传文件
2. 写Xml文件
3. 文件拷贝
1. //上传
protected void picUp_Click(object sender, EventArgs e)
{
......