分享

asp生成xml问题

 颐中八喜 2011-08-03
数据库 是access 有song 的表一个 "song"里的字段有 id name(歌名) img(图片地址) url (歌曲地址) singer(歌手) lrc(歌词) 想要按以下格式生成xml文件的 asp代码如何写啊? 本人菜鸟一个 希望多多指教啊

<?xml version="1.0" encoding="utf-8"?>
<msg>
<list pic_url="图片地址" title="歌名" singer="歌手" lrc_url="歌词" >
<u u="歌曲地址" />
</list>
</msg>

数据库连接文件在网站根目录下有conn.asp

conn.asp 代码是
<%
dim conn
dim dbpath
set conn=server.createobject("adodb.connection")
DBPath = Server.MapPath("data/#data_aboutplayer.mdb")
conn.Open "driver={Microsoft Access Driver (*.mdb)};dbq=" & DBPath
%>
_____________________________________________________________________________________________________________
 
Dim xmlDoc,msgRs,sql,Node,Node1
sql = "select * from song order by Id"
Set msgRs = Server.CreateObject("ADODB.Recordset")
msgRs.open sql,conn,1,1
If not msgRs.eof then
Set xmlDoc = Server.CreateObject("Msxml2.FreeThreadedDOMDocument.3.0")
xmlDoc.AppendChild(xmlDoc.CreateNode(1,"msg",""))
while not msgRs.eof
Set Node = xmlDoc.CreateNode(1,"list","")
xmlDoc.DocumentElement.AppendChild(Node)
Node.SetAttribute "pic_url",msgRs("img")
Node.SetAttribute "title",msgRs("name")
Node.SetAttribute "singer",msgRs("singer")
Node.SetAttribute "lrc_url",msgRs("lrc")
Set Node1 = xmlDoc.CreateNode(1,"u","")
Node.AppendChild(Node1)
Node1.SetAttribute "u",msgRs("url")
msgRs.movenext
wend
xmlDoc.save(server.MapPath("song.xml"))
Set xmlDoc = nothing
Set Node = nothing
Set Node1 = nothing
End If
Set msgRs = Nothing
 

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多