最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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過(guò)程測(cè)試通過(guò) 
  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過(guò)程測(cè)試通過(guò) 
  '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ì)展開(kāi)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不是主要問(wèn)題,還是用實(shí)體類整個(gè)的寫入更新吧,畢竟數(shù)據(jù)的完整性是第一位的。
如是文章類的,對(duì)該目錄建一個(gè)xml索引文件來(lái)存放文章的編號(hào),url等,用xml的attribute作為標(biāo)記不同字段,內(nèi)容頁(yè)面可以用另外的html或xml頁(yè)面存放,用linq to xml操作數(shù)據(jù),效率不是很差,個(gè)人觀點(diǎn)。當(dāng)搜索時(shí)候只要查詢指定文件名xml或文件類型就可以了。

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

相關(guān)文章

最新評(píng)論

威信县| 江门市| 东源县| 十堰市| 康马县| 屏东县| 曲麻莱县| 呼伦贝尔市| 沙湾县| 屏东市| 油尖旺区| 广宁县| 奉贤区| 黑龙江省| 北票市| 新竹市| 新化县| 平潭县| 朝阳县| 长顺县| 瓦房店市| 民丰县| 莲花县| 固原市| 博野县| 剑河县| 容城县| 延寿县| 钟祥市| 互助| 卓尼县| 得荣县| 静乐县| 齐齐哈尔市| 迭部县| 华阴市| 宁化县| 霍邱县| 五寨县| 习水县| 静海县|