C#实现提高xml读写速度的方法

2019-12-26 12:01:22刘景俊
易采站长站为您分析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)