C#完成進步xml讀寫速度的辦法。本站提示廣大學習愛好者:(C#完成進步xml讀寫速度的辦法)文章只能為提供參考,不一定能成為您想要的結果。以下是C#完成進步xml讀寫速度的辦法正文
本文實例講述了C#完成進步xml讀寫速度的辦法。分享給年夜家供年夜家參考。詳細完成辦法以下:
dim domxmldocument as system.xml.xmldocument
dim tmppath as string = apptempfilepath
dim xmlfile as string = tmppath + "\testxml.xml"
'窗體加載事宜
private sub testxml_load(byval sender as system.object, byval e as system.eventargs) handles mybase.load
'讀xml進程測試經由過程
dim domxmldocument as system.xml.xmldocument
dim tmppath as string = apptempfilepath
dim xmlfile as string = tmppath + "\testxml.xml"
dim reader as system.xml.xmlreader = nothing
try
reader = new xml.xmltextreader(xmlfile)
'reader.
while reader.read
me.lboxxml.items.add(reader.name + reader.value)
end while
catch ex as exception
msgbox(ex.message)
finally
if not (reader is nothing) then
reader.close()
end if
end try
end sub
'載入xml事宜
private sub btnxmlload_click(byval sender as system.object, byval e as system.eventargs) handles btnxmlload.click
'me.lboxxml.items.clear()
''讀xml進程測試經由過程
'dim reader as system.xml.xmlreader = nothing
'try
' reader = new xml.xmltextreader(xmlfile)
' while reader.read
' me.lboxxml.items.add(reader.name + ":" + reader.value)
' end while
'catch ex as exception
' msgbox(ex.message)
'finally
' if not (reader is nothing) then
' reader.close()
' end if
'end try
dim ds as new dataset
try
'假如直接應用ds做datasource則不會睜開datagrid,用dv則能直接顯示准確。
ds.readxml(xmlfile)
dim tb as datatable
dim dv as dataview
tb = ds.tables(0)
dv = new dataview(tb)
datagrid1.datasource = dv
'datagrid1.datamember = "testxmlmember"
'datagrid1.datamember = "employeefname"
'dim dxd as new xmldatadocument
catch ex as exception
msgbox(ex.message.tostring)
end try
end sub
'保留新建xml內容事宜
private sub btnsavenew_click(byval sender as system.object, byval e as system.eventargs) handles btnsavenew.click
dim mytw as new xmltextwriter(tmppath + "\testxmlwrite.xml", nothing)
mytw.writestartdocument()
mytw.formatting = formatting.indented
mytw.writestartelement("team")
mytw.writestartelement("player")
mytw.writeattributestring("name", "george zip")
mytw.writeattributestring("position", "qb")
mytw.writeelementstring("nickname", "zippy")
mytw.writeelementstring("jerseynumber", xmlconvert.tostring(7))
mytw.writeendelement()
mytw.writeendelement()
mytw.writeenddocument()
mytw.close()
end sub
文件很年夜的情形下,可以斟酌手動完成數據更新適配器,好比手動完成一個xml節點搜刮/更新,如許就不消重寫全部xml。
假如法式的i/o不是重要成績,照樣用實體類全部的寫入更新吧,究竟數據的完全性是第一名的。
如是文章類的,對該目次建一個xml索引文件來寄存文章的編號,url等,用xml的attribute作為標志分歧字段,內容頁面可以用別的的html或xml頁面寄存,用linq to xml操作數據,效力不是很差,小我不雅點。當搜刮時刻只需查詢指定文件名xml或文件類型便可以了。
願望本文所述對年夜家的C#法式設計有所贊助。