VB to generate XML format files

Source: Internet
Author: User
Tags date format count end
xml| Generate XML

Dim oFSO as New FileSystemObject
Dim Ofile as Object
Dim xmldoc as MSXML2. DOMDocument

Nowdate = CStr (year (date)) & CStr (Month (date)) & CStr (date)
Epath = Exppath.text + "\" + nowdate

Set xmldoc = New MSXML2. DOMDocument
Xmldoc.validateonparse = False
Xmldoc.async = False

Set oFSO = CreateObject ("Scripting.FileSystemObject")
If ofso.fileexists (Epath + ". xml") Then
Ofso.deletefile Epath + ". Xml"
End If
Set ofile = ofso.opentextfile (Epath + ". Xml", 8, True)

Dim Str as String
str = "Select AJBH from Gab_mala where ifexp is null or ifexp=" "
oRS.Open str, oconn, 1, 1

Do as not ors.eof

Tempzdaj = "<zdaj:record ajbh=" + oRs ("AJBH") + "' ><ma><la>"
Ofile.writeline (Tempzdaj)

' Basic information
str = "Select Xckybh,ladwdm,ladwxc,ajlb1,ajlb2,ajlb3,ajxz1,larq,swrs,ssrs,fxdz,fxdzxz,fxcs,fxbw,zwyw,dnayw,"
str = str + "Zjyw,xdhwyw,gj,gjhj,qthjwz,bjwp,zasjsx,zasjxx,fxzarscz,fxzarszz,zagj,qhdx,srcs,qrfs,jcfs,srfs,"
str = str + "Wzmj,tlfs,zasdtdms,aqms,zayy,lcfzyj,zazzhzbzcy,lxdh,xsjsfzr,gajgfzr,tbr,tbrq from Gab_mala where Ajbh= '" & Amp ORs ("AJBH") & "'"
Orstemp.open str, oconn, 1, 1

Do as not orstemp.eof
Set root = Xmldoc.createnode (1, "jbxx", "")
Set temp = xmldoc.appendchild (root)

Set Onode = Xmldoc.createnode ("element", "rec", "")
Set temp = root.appendchild (onode)

For i = 0 to Orstemp.fields.count-1

Set child = Xmldoc.createnode ("element", Orstemp.fields (i). Name, "")

If not IsNull (Orstemp.fields (i)) Then
If Orstemp.fields (i). Name = UCase ("Fxcs") Or orstemp.fields (i). Name = UCase ("FXBW") Or orstemp.fields (i). Name = UCase ("Zagj") Or orstemp.fields (i). Name = UCase ("QHDX") Or orstemp.fields (i). Name = UCase ("SRCs") Or orstemp.fields (i). Name = UCase ("Qrfs") Or orstemp.fields (i). Name = UCase ("Jcfs") Or orstemp.fields (i). Name = UCase ("SRFs") Or orstemp.fields (i). Name = UCase ("WZMJ") Or orstemp.fields (i). Name = UCase ("Zayy") Then
Child. Text = CL (Orstemp.fields (i))
Else
Child. Text = Orstemp.fields (i)
End If
Else
Child. Text = ""
End If

Set temp = onode.appendchild (Child)
Next

Rstoxml = Root.xml

Ofile.writeline (Rstoxml)
Xmldoc.removechild (Root)

Orstemp.movenext
Loop
Orstemp.close

' Personnel

str = "Select Manid from Caseman where caseno= '" & ORs ("AJBH") & "'"
Ors1.open str, oconn, 1, 1

If ors1.recordcount > 0 Then
Set root = Xmldoc.createnode (1, "Xyry", "")
Set temp = xmldoc.appendchild (root)
End If

Do as not ors1.eof
str = "Select Ztrybh,name as xm,othername as bmhch,sex as xb,birthday as csrqsx,birthday as csrqxx,jzd as hjd,abodeaddr as" Hjdxz,stature as sgsx,stature as sgxx,accent as ky,bodyshape as tmtz,faceshape as TBBJ, ' as qttz,spec as Zc,CARDID as SF En, ' as QTZJMC, ' as QTZJHM, ' as ZP from Smaninfo '
str = str + "where manid= '" & ORs1 ("Manid") & "'"
Orstemp.open str, oconn, 1, 1

Do as not orstemp.eof


Set Onode = Xmldoc.createnode ("element", "rec", "")
Set temp = root.appendchild (onode)

For i = 0 to Orstemp.fields.count-1

Set child = Xmldoc.createnode ("element", Orstemp.fields (i). Name, "")

If not IsNull (Orstemp.fields (i)) Then
If Orstemp.fields (i). Name = UCase ("KY") Or orstemp.fields (i). Name = UCase ("Tmtz") Or orstemp.fields (i). Name = UCase ("TBBJ") Or orstemp.fields (i). Name = UCase ("Zc") Then
Child. Text = CL (Orstemp.fields (i))
Else
If Orstemp.fields (i). Name = UCase ("csrqsx") Or orstemp.fields (i). Name = UCase ("csrqxx") Then
Child. Text = Cldate (Orstemp.fields (i))
Else
If Orstemp.fields (i). Name = UCase ("ZTRYBH") Then
Child. Text = "T" + orstemp.fields (i)
Else
Child. Text = Orstemp.fields (i)
End If
End If
End If
Else
Child. Text = ""
End If

Set temp = onode.appendchild (Child)
Next

Orstemp.movenext
Loop
Orstemp.close

Ors1.movenext
Loop

If ors1.recordcount > 0 Then
Rstoxml = Root.xml
Ofile.writeline (Rstoxml)
Xmldoc.removechild (Root)
End If

Ors1.close

Tempzdaj = "</la></ma></zdaj:record>"
Ofile.writeline (Tempzdaj)
Ors.movenext

Loop

Ors.close

Set ofso=nothing



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.