代碼如下
using System
using System
using System
using System
using System
using System
using System
namespace XMLDOMDemo
{
public partial class Form
{
public Form
{
InitializeComponent();
}
private void btnLoad_Click(object sender
{
XmlDocument xmlDoc = new XmlDocument();
xmlDoc
MessageBox
}
//創建文檔
private void btnCreate_Click(object sender
{
XmlDocument xmlDoc = new XmlDocument();
//建立Xml的定義聲明
XmlDeclaration dec = xmlDoc
xmlDoc
//創建根節點
XmlElement root = xmlDoc
xmlDoc
XmlNode book = xmlDoc
XmlElement title = xmlDoc
title
book
XmlElement isbn = xmlDoc
isbn
book
XmlElement author = xmlDoc
author
book
XmlElement price = xmlDoc
price
price
book
root
xmlDoc
}
private void btnInsert_Click(object sender
{
XmlDocument xmlDoc = new XmlDocument();
xmlDoc
XmlNode root = xmlDoc
XmlElement book = xmlDoc
XmlElement title = xmlDoc
title
book
XmlElement isbn = xmlDoc
isbn
book
XmlElement author = xmlDoc
author
book
XmlElement price = xmlDoc
price
price
book
root
xmlDoc
MessageBox
}
private void btnUpdate_Click(object sender
{
XmlDocument xmlDoc = new XmlDocument();
xmlDoc
//
//獲取Books節點的所有子節點
XmlNodeList nodeList = xmlDoc
//遍歷所有子節點
foreach (XmlNode xn in nodeList)
{
//將子節點類型轉換為XmlElement類型
XmlElement xe = (XmlElement)xn;
if (xe
{
xe
}
if (xe
{
xe
}
}
xmlDoc
}
private void btnDelete_Click(object sender
{
XmlDocument xmlDoc = new XmlDocument();
xmlDoc
XmlNodeList nodeList = xmlDoc
//遍歷所有子節點
foreach (XmlNode xn in nodeList)
{
//將子節點類型轉換為XmlElement類型
XmlElement xe = (XmlElement)xn;
if (xe
{
xe
}
if (xe
{
xe
}
}
xmlDoc
}
}
}
From:http://tw.wingwit.com/Article/program/net/201311/11947.html