Asp.net operation XML write XML data writexml in the specified format

Source: Internet
Author: User

CopyCode The Code is as follows: private sub writexml ()
Try
Create (strfname, "newdataset ")
Savexmlfile ("GG", "newdataset", true)
Catch ex as exception
Msgbox (ex. Message)
End try
End sub
Private function create (byval filename as string, byval root as string) as Boolean
Dim newxml as xmltextwriter = nothing
Irowcount = objdataset. Tables ("dataanalyseview"). Rows. Count
Icolcount = objdataset. Tables ("dataanalyseview"). Columns. Count
Try
Newxml = new xmltextwriter (filename, nothing)
Newxml. Formatting = formatting. indented
Newxml. writestartdocument ()
Newxml. writecomment (My. application. info. assemblyname & "Settings") 'project name
Newxml. writestartelement (Root)
Newxml. writestartelement (objdataset. Tables ("dataanalyseview"). tablename. tostring ())
Newxml. writestartelement (objdataset. Tables ("dataanalyseview"). columns (2). columnname (). tostring ())
Newxml. writestring (objdataset. Tables ("serialnumbertable"). Rows (txtn) ("serialnumber"). tostring ())
Newxml. writeendelement ()
Newxml. writestartelement (objdataset. Tables ("dataanalyseview"). Columns (3). columnname (). tostring ())
Newxml. writestring (objdataset. Tables ("dataanalyseview"). Rows (0) ("client"). tostring ())
Newxml. writeendelement ()
Newxml. writestartelement (objdataset. Tables ("dataanalyseview"). Columns (5). columnname (). tostring ())
Newxml. writestring (objdataset. Tables ("dataanalyseview"). Rows (0) ("productor"). tostring ())
Newxml. writeendelement ()
Newxml. writestartelement (objdataset. Tables ("dataanalyseview"). columns (6). columnname (). tostring ())
Newxml. writestring (objdataset. Tables ("dataanalyseview"). Rows (0) ("model"). tostring ())
Newxml. writeendelement ()
Newxml. writestartelement (objdataset. Tables ("dataanalyseview"). Columns (4). columnname (). tostring ())
Newxml. writestring (objdataset. Tables ("dataanalyseview"). Rows (0) ("stationname"). tostring ())
Newxml. writeendelement ()
Newxml. writestartelement (objdataset. Tables ("dataanalyseview"). Columns (7). columnname (). tostring ())
Newxml. writestring (objdataset. Tables ("dataanalyseview"). Rows (0) ("datatime"). tostring ())
Newxml. writeendelement ()
Newxml. writestartelement (objdataset. Tables ("dataanalyseview"). Columns (8). columnname (). tostring ())
Newxml. writestring (objdataset. Tables ("dataanalyseview"). Rows (0) ("status"). tostring ())
Newxml. writeendelement ()
Newxml. writeendelement ()
Progressbar1.step = 1
Progressbar1.value = 1
Progressbar1.visible = true
For irow = 0 to irowcount-1
SS (irowcount-1)
Newxml. writestartelement (objdataset. Tables ("dataanalyseview"). tablename. tostring ())
For icol = 0 to icolcount-1
If icol <2 or icol> 7 then
Newxml. writestartelement (objdataset. Tables ("dataanalyseview"). Columns (icol). columnname (). tostring)
Newxml. writestring (objdataset. Tables ("dataanalyseview"). Rows (irow) (icol). tostring ())
Newxml. writeendelement ()
End if
Next
Newxml. writeendelement ()
Next
Newxml. writeendelement ()
Newxml. writeendelement ()
Newxml. Flush ()
Newxml. Close ()
Catch ex as exception
Debug. Print ("Create-" & Ex. Message)
Return false
Finally
If newxml isnot nothing then
Newxml. Close ()
Newxml = nothing
End if
End try
Return true
End Function
Private function savexmlfile (byval asection as string, byval akey as string, byval avalue as string) as Boolean
Dim paths () as string
Dim N as integer
Dim node, node2 as xmlnode
Dim ele as xmlelement
While strings. Left (asection, 1) = "/"
Asection = strings. mid (asection, 2)
End while
If asection = "" then
Xmldoc. documentelement. removeall ()
Else
Paths = strings. Split (asection ,"/")
Try
Node = xmldoc. documentelement. selectsinglenode (paths (n ))
If node is nothing then
Ele = xmldoc. createelement (paths (n ))
Node = xmldoc. documentelement. appendchild (Ele)
End if
For n = 1 to paths. Length-1
If paths (n) = "" Then continue
Node2 = node. selectsinglenode (paths (n ))
If node2 is nothing then
Ele = xmldoc. createelement (paths (n ))
Node2 = node. appendchild (Ele)
End if
Node = node2
Next
If akey = "" then
Node. removeall ()
Else
Ele = node. Item (akey)
If ELE is nothing then
Ele = xmldoc. createelement (akey)
Node. appendchild (Ele)
End if
If avalue = "" then
Node. removechild (Ele)
Else
Ele. innertext = avalue
End if
End if
Catch ex as exception
Debug. Print (ex. Message)
Return false
End try
End if
Xmldoc. Save (strfilename)
End Function
Related Article

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.