C # methods to improve XML read and write speed

Source: Internet
Author: User

Dim domxmldocument As System.Xml.XmlDocument
Dim Tmppath As String = Apptempfilepath
Dim xmlfile As String = Tmppath + "\testxml.xml"

' Form Load Event
Private Sub Testxml_load (ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
' Read XML process test through
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 are nothing) then
Reader.close ()
End If
End Try
End Sub
' Load XML events
Private Sub Btnxmlload_click (ByVal sender As System.Object, ByVal e As System.EventArgs) handles Btnxmlload.click
' Me.lboxxml.items.clear ()
"Read the XML process test through
' 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 are nothing) then
' Reader.close ()
' End If
' End Try
Dim ds As New DataSet
Try
' If you use DS to do DataSource, you will not expand the DataGrid, with DV you can directly display the correct.
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
' Save new XML content Event
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

In large files, consider manually implementing a data update adapter, such as manually implementing an XML node search/update, so that you do not have to rewrite the entire XML.
If the program's I/O is not a major problem, or the entire write update with the entity class, after all, the integrity of the data is the first.

If the article class, the directory to build an XML index file to store the number of articles, URLs, and so on, using XML attributes as tags in different fields, content pages can be stored in another HTML or XML pages, using LINQ to XML data, the efficiency is not very poor, personal point of view. When searching, it's OK to just query for the filename XML or file type.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.