---
title: "asp生成xml"
author: "lokepaqi"
date: "2011-05-24T16:45:08Z"
tags: ["ASP", "F#", "XML"]
categories: ["Web前端"]
slug: "asp-xml"
draft: false
lastmod: "2011-05-24T16:45:08Z"
id: 1056813
url: "https://hqlly.iteye.com/blog/1056813"
---

&lt;!-- #include file="\_connection.asp" --&gt;  
&lt;%

Set rs = Server.CreateObject("ADODB.Recordset")  
rs.open "select * from \_user ",conn,3,2

total=rs.recordcount

'------------------生成xml  
Set f = Server.CreateObject("Scripting.FileSystemObject")  
files = "output.xml" '文件输出路径  
Set myfile = f.Createtextfile(server.mappath(files),true)  
myfile.writeline "&lt;?xml version=""1.0"" encoding=""UTF-8""?&gt;"  
myfile.writeline "&lt;Document&gt;"

do while not rs.Eof  
myfile.writeline "&lt;user&gt;"  
myfile.writeline "&lt;ID&gt;"&rs("id")&"&lt;/ID&gt;"  
myfile.writeline "&lt;username&gt;"&rs("username")&"&lt;/username&gt;"  
myfile.writeline "&lt;sex&gt;"&rs("sex")&"&lt;/sex&gt;"  
myfile.writeline "&lt;/user&gt;"  
rs.MoveNext()  
loop  
myfile.writeline "&lt;/Document&gt;"  
myfile.close

response.write "success"  
%&gt;