欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

C#實(shí)現(xiàn)提高xml讀寫速度的方法

 更新時(shí)間:2014年11月03日 09:25:52   投稿:shichen2014  
這篇文章主要介紹了C#實(shí)現(xiàn)提高xml讀寫速度的方法,并且針對(duì)各類文件的讀寫做了較為細(xì)致的分析,非常實(shí)用,需要的朋友可以參考下

本文實(shí)例講述了C#實(shí)現(xiàn)提高xml讀寫速度的方法。分享給大家供大家參考。具體實(shí)現(xiàn)方法如下:

復(fù)制代碼 代碼如下:
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過程測(cè)試通過 
  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過程測(cè)試通過 
  '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則不會(huì)展開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內(nèi)容事件 
  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

文件很大的情況下,可以考慮手動(dòng)實(shí)現(xiàn)數(shù)據(jù)更新適配器,比如手動(dòng)實(shí)現(xiàn)一個(gè)xml節(jié)點(diǎn)搜索/更新,這樣就不用重寫整個(gè)xml。
如果程序的i/o不是主要問題,還是用實(shí)體類整個(gè)的寫入更新吧,畢竟數(shù)據(jù)的完整性是第一位的。
如是文章類的,對(duì)該目錄建一個(gè)xml索引文件來存放文章的編號(hào),url等,用xml的attribute作為標(biāo)記不同字段,內(nèi)容頁面可以用另外的html或xml頁面存放,用linq to xml操作數(shù)據(jù),效率不是很差,個(gè)人觀點(diǎn)。當(dāng)搜索時(shí)候只要查詢指定文件名xml或文件類型就可以了。

希望本文所述對(duì)大家的C#程序設(shè)計(jì)有所幫助。

相關(guān)文章

  • C#中HttpWebRequest的用法詳解

    C#中HttpWebRequest的用法詳解

    這篇文章主要介紹了C#中HttpWebRequest的用法,以實(shí)例的形式詳細(xì)敘述了HttpWebRequest類中GET與POST的用法,非常具有參考借鑒價(jià)值,需要的朋友可以參考下
    2014-11-11
  • C#獲取本機(jī)IP地址(ipv4)

    C#獲取本機(jī)IP地址(ipv4)

    本文主要介紹了C#獲取本機(jī)所有IP地址的方法、C#獲取本機(jī)IP地址(ipv4)的方法等。具有很好的參考價(jià)值。下面跟著小編一起來看下吧
    2017-03-03
  • winform實(shí)現(xiàn)關(guān)閉按鈕失效的兩種方法

    winform實(shí)現(xiàn)關(guān)閉按鈕失效的兩種方法

    這篇文章主要介紹了winform實(shí)現(xiàn)關(guān)閉按鈕失效的兩種方法,實(shí)例分析了WinForm實(shí)現(xiàn)關(guān)閉按鈕失效的原理與所涉及的相關(guān)技巧,需要的朋友可以參考下
    2015-09-09
  • 解答“60k”大佬的19道C#面試題(上)

    解答“60k”大佬的19道C#面試題(上)

    這篇文章主要解答了“60k”大佬的19道C#面試題中的10道,文中的面試題比較小眾,作者給了不錯(cuò)的答案,相信對(duì)你以后的面試有所幫助,感興趣就來了解下
    2020-06-06
  • C#多線程用法詳解

    C#多線程用法詳解

    本文詳細(xì)講解了C#多線程用法,文中通過示例代碼介紹的非常詳細(xì)。對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2021-12-12
  • C#實(shí)現(xiàn)求一組數(shù)據(jù)眾數(shù)的方法

    C#實(shí)現(xiàn)求一組數(shù)據(jù)眾數(shù)的方法

    這篇文章主要介紹了C#實(shí)現(xiàn)求一組數(shù)據(jù)眾數(shù)的方法,這里以浮點(diǎn)型數(shù)組為例分析了C#求眾數(shù)的算法原理與實(shí)現(xiàn)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下
    2015-08-08
  • C# 使用WPF 用MediaElement控件實(shí)現(xiàn)視頻循環(huán)播放

    C# 使用WPF 用MediaElement控件實(shí)現(xiàn)視頻循環(huán)播放

    在WPF里用MediaElement控件,實(shí)現(xiàn)一個(gè)循環(huán)播放單一視頻的程序,同時(shí)可以控制視頻的播放、暫停、停止。這篇文章給大家介紹了C# 使用WPF 用MediaElement控件實(shí)現(xiàn)視頻循環(huán)播放,需要的朋友參考下吧
    2018-04-04
  • C#使用正則表達(dá)式過濾html標(biāo)簽

    C#使用正則表達(dá)式過濾html標(biāo)簽

    最近在開發(fā)一個(gè)項(xiàng)目,其中有需求要求我們把一段html轉(zhuǎn)換為一般文本返回,使用正則表達(dá)式是明智的選擇,下面小編給介紹下C#使用正則表達(dá)式過濾html標(biāo)簽,需要的朋友參考下
    2016-08-08
  • ListView用法中與滾動(dòng)相關(guān)的需求實(shí)現(xiàn)

    ListView用法中與滾動(dòng)相關(guān)的需求實(shí)現(xiàn)

    這篇文章主要介紹了ListView用法中與滾動(dòng)相關(guān)的需求實(shí)現(xiàn),獲取并設(shè)置ListView的滾動(dòng)位置,以及獲取滾動(dòng)位置處的項(xiàng)目,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-06-06
  • c#注冊(cè)客戶端事件示例

    c#注冊(cè)客戶端事件示例

    這篇文章主要介紹了c#注冊(cè)客戶端事件使用示例,大家參考使用吧
    2014-01-01

最新評(píng)論