asp動態生成xml

<!--#include file="../inc/conn.asp" -->
<%
dim rs,sql,id,title,url,strTemp

id=Request.QueryString("id")
title=request.Form("title")
url=request.Form("url")

if id<>"" then
	sql="select * from [videos] where id="&id
else
	sql="select * from [videos] where id is null"
end if
set rs = Server.CreateObject("adodb.recordset")
rs.open sql,conn,1,3
if id="" then rs.addnew
rs("title")=title
rs("url")=url
rs.update
rs.close

strTemp="<?xml version=""1.0"" encoding=""utf-8""?>"
strTemp=strTemp&"<playlist version=""1"" xmlns=""http://xspf.org/ns/0/"">"
strTemp=strTemp&"<trackList>"
rs.open "select * from videos",conn,1,1
if not rs.eof then
	while not rs.eof
		strTemp=strTemp&"<track>"
		strTemp=strTemp&"<title>"&rs("title")&"</title>"
		strTemp=strTemp&"<location>"&rs("url")&"</location>"
		strTemp=strTemp&"</track>"
	  rs.movenext
	wend
end if
rs.close
set rs=nothing
strTemp=strTemp&"</trackList>"
strTemp=strTemp&"</playlist>"

Function saveXml(Text,FileName)    
	dim xmldoc,path 
	set xmldoc= server.CreateObject("MSXML.DOMDocument") 
	path = Server.MapPath(FileName) 
	xmldoc.LoadXML(Text) 
	xmldoc.save(path) 
	set xmldoc= nothing
End Function

call saveXml(strTemp,"../playlist.xml")
strUrl=request.ServerVariables("HTTP_REFERER") 
Response.Write("<script>alert('操作成功!');location.href='"&strUrl&"';</script>")

%>

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章