ASP动态生成XML的实现方法 - TOMMYHU - 专注互联网开发及运营技术,提供相关资料及软件下载,奇趣网络时事评论!
Apr 16

ASP动态生成XML的实现方法 不指定

tommyhu , 18:10 , ASP , Comments(0) , Trackbacks(0) , Reads(8780) , Via Original Large | Medium | Small
确认目录有写权限

<!--#include virtual="conn/conndb.asp"-->
<%
strC = "<?xml version=""1.0"" encoding=""utf-8""?> " & vbcrlf
strC = strC&" <list>" & vbcrlf    

set rs = server.CreateObject("adodb.recordset")
sql = "select top 10 name,pic,d,summary from database where flag=1"    
rs.open sql,conn,1,1
do while not rs.eof
src="http://tommyhu.cn/piaoupload/"&rs(1)
link="http://tommyhu.cn/list-"&rs(2)&".html"
    strC = strC&"<img1 title='"&rs(0)&"' src='"&src&"' link='"&link&"' description='"&left(rs(3),10)&"' />"& vbcrlf
rs.movenext
loop
rs.close
strC = strC&"</list>" & vbcrlf    


call saveXml(strC,"test.xml")
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

%>


参考代码

<!--#include file="conn.asp"-->


<%
strC = "<?xml version=""1.0"" encoding=""utf-8""?> " & vbcrlf
strC = strC&" <root>" & vbcrlf    

set rs = server.CreateObject("adodb.recordset")
set rs1 = server.CreateObject("adodb.recordset")
sql = "select anclassid,anclass from bsort order by anclassidorder"    
rs.open sql,conn,1,1
do while not rs.eof
    strC = strC&"<bigsort anclassid='"&rs(0)&"' name='"&rs(1)&"' >"& vbcrlf
    sql1 = "select nclassid,nclass from ssort where anclassid = "&rs(0)&" order by nclassidorder"
    rs1.open sql1,conn,1,1
    do while not rs1.eof
    strC = strC&"<ssort id='"&rs1(0)&"' name='"&rs1(1)&"'>"&rs1(1)&" </ssort>"& vbcrlf
    rs1.movenext
    loop
    rs1.close
    strC = strC&"</bigsort>"& vbcrlf
rs.movenext
loop
rs.close
strC = strC&" </root>" & vbcrlf    

call saveXml(strC,"111111.xml")

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
%>

▲返回顶部

Add a comment

Nickname

emotemotemotemotemotemotemotemotemotemotemotemotemotemotemotemot