上次操作這東西還是第乙個專案裡面,為了讀取xml檔案裡面的大量的資料操作這東西。
現在突然要寫這東西雖然很簡單,還是有點生疏,寫個demo以備查閱。後面再linq to xml就簡單很多。
使用的xml檔案demo.xml:
<?xml version="1.0" encoding="utf-8"
?>
<
connectionstrings
>
<
connectionstring
id="connstr1"
>
<
serveraddress
>127.0.0.1
serveraddress
>
<
database
>test
database
>
<
userid
>sa
userid
>
<
password
>111222
password
>
connectionstring
>
<
connectionstring
id="connstr2"
>
<
serveraddress
>127.0.0.1
serveraddress
>
<
database
>test
database
>
<
userid
>sa
userid
>
<
password
>111222
password
>
connectionstring
>
connectionstrings
>
然後是操作xml的類xmloperatordemo.cs:
usingsystem;
using
system.collections.generic;
using
system.linq;
using
system.text;
using
system.xml;
namespace
testdemo
public
void
getnodevalue()
}public
void
setnodevalue()
public
void
deletenode()
}}
測試主方法:
staticvoid main(string
args)
c 操作xml檔案
dataset ds new dataset ds.readxml basepath config.xml 讀取xml檔案 label1.text ds.tables time rows 0 ta tostring 讀取xml檔案資料 ds.tables time rows 0 ta ta new ...
c 操作XML檔案
匯入命名空間 using system.xml 功能演示 例項化檔案物件 xmldocument xd newxmldocument 物件載入xml檔案 xd.load fullchannels.xml 讀取根節點 xmlnode root xd.documentelement 獲取節點名稱 con...
c 操作XML檔案 1614260503
using system.xml 例項化檔案物件 xmldocument xd newxmldocument 物件載入xml檔案 xd.load fullchannels.xml 讀取根節點 xmlnode root xd.documentelement 獲取節點名稱 console.writeli...