通过DataSet 来读写XML的相关代码,整理了一下。
内容比较简单,也最基础。 mark一下,以后查阅用。
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.IO;
using System.Xml;
using System.Xml.XPath;
namespace WindowsApplication2
{
class XmlReader
{
private string _filePath = @"C:\Test.xml";
// 读取XML
public void ReadXmlFile()
{
if (File.Exists(_filePath))
{
DataSet ds = new DataSet();
ds.ReadXml(_filePath);
if (ds.Tables["MyTable"] != null)
{
DataTable dt = ds.Tables["MyTable"];
for (int i = 0; i < dt.Rows.Count; i++)
{
string str1 = dt.Rows[i]["Data1"].ToString(); //取得结点1的值
string str2