ASP to generate XML format of database data in a method

Source: Internet
Author: User
Tags format end
xml| Generate xml| Data | database

<%
Set Xmldoc=server.createobject ("MSXML2. DOMDocument ")
Set Obj=server.createobject ("Gdcom.database")
Set Rs=server.createobject ("Adodb.recordset")
Set fso = CreateObject ("Scripting.FileSystemObject")
Xmldoc.async=false
XmlDoc. Validateonparse=false
Str= "Select Code,pyt,detail from zdb where kind= ' 92 '"
Set Rs=obj.runsqlreturnrs (str)
Set AddFile = fso. CreateTextFile (Server.MapPath (".") & "\20060801.xml", True)
Set root = Xmldoc.createnode (1, "book", "Record")
Set temp = xmldoc.appendchild (root)
Set objnodeattr = xmldoc. CreateAttribute ("AJBH")
Objnodeattr.value = "A2107270006002004080001"
XmlDoc. Documentelement.setattributenode (objnodeattr)


Set ajlx= Xmldoc.createnode ("element", "Ma", "")
Set temp = root.appendchild (AJLX)

Set ajlb= Xmldoc.createnode ("element", "La", "")
Set temp = ajlx.appendchild (AJLB)

 if not Rs. EOF Then
    Rs. MoveFirst
  while (not Rs. EOF)
    Set onode = Xmldoc.createnode ("element", "rec", "")    
     Set temp = ajlb.appendchild (onode)
 
    for i = 0 to Rs. Fields.count-1
      Set child = Xmldoc.createnode ("element", Rs. Fields (i). Name, "")
     
    If not IsNull (Rs. Fields (i)) Then
        Child. Text = Rs. Fields (i)
    Else
        Child. Text = ""
    end If
     
      Set temp = Onode.appendchild (Child)
    Next

Rs. MoveNext
Wend
Rstoxml = Root.xml
Else
Rstoxml = ""
End If
AddFile. WriteLine (Rstoxml)
Addfile.close
Set fso=nothing
Response.Write ("ok!")
%>



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.