ASP更新生成XML文件!!!
我的网站是用一个FLASH加载XML实现音乐在线播放,每次用FTP上传音乐和修改XML很麻烦,,,想用ASP实现动态更新XML文件某再次求助各位高手!!!
现在网站的XML如下:
其中,album name的内容来自数据表“lanmu”,song name的内容来自数据表“songs”,数据库是access!!!xml路径是/player/xml/list.xml
谢谢各位!!
<?xml version="1.0" encoding="utf-8"?>
<featureset>
<album name="Paper Trail" author="TI" imageUrl="images/TI/image.jpg">
<song name="56 Bars (Intro)" duration="0 : 34" buy="false" download="true" buyLink="http://www.flabell.com/" downloadSource="player/download/song1.mp3">songs/song3.mp3</song>
<song name="I'm Illy" duration="3 : 28" buy="false" download="true" buyLink="http://www.flabell.com/" downloadSource="player/download/song1.mp3">songs/song3.mp3</song>
<song name="Ready For Whatever" duration="3 : 54" buy="false" download="true" buyLink="http://www.flabell.com/" downloadSource="player/download/song1.mp3">songs/song3.mp3</song>
<song name="On Top Of The World" duration="3 : 24" buy="false" download="true" buyLink="http://www.flabell.com/" downloadSource="player/download/song1.mp3">songs/song3.mp3</song>
</album>
</featureset>
------解决方案--------------------参考:
<%
'利用Stream组件写入文件过程
Sub WriteToTextFile(ByVal FileUrl,ByVal Str,ByVal CharSet)
With Server.CreateObject("ADODB.Stream")
.Type = 2
.Mode = 3
.Charset = CharSet
.Open
.WriteText str
.SaveToFile FileUrl,2
.Flush
.Close
End With
End Sub
If trim(request.Form("action")) = "do" then Call CreateXml()
Sub CreateXml()
dim rs,sql,xmlData
'以下为调用数据库数据编写xml结构,装入变量xmlData
Set rs = Server.CreateObject("ADODB.RecordSet")
sql = "select id,Title from News order by id desc"
rs.open sql,conn,0,1
xmlData = "<?xml version=""1.0"" encoding=""utf-8""?>" & vbNewLine
xmlData = xmlData & "<root>" & vbNewLine
Do while not rs.eof
xmlData = xmlData & "<news id=""" & rs("id") & """ title=""" & rs("Title") & """ />" & vbNewLine
rs.movenext()
Loop
xmlData = xmlData & "</root>"
rs.close()
Set rs = Nothing
'xml编写完成
Call WriteToTextFile(Server.MapPath("/news.xml"),xmlData,"UTF-8") '调用WriteToTextFile过程将xml文本写入xml文件
conn.close()
Set conn = Nothing
response.Write("<script>alert('更新成功!');window.location.href = 'index.asp';</script>")
response.End()
End Sub
%>
------解决方案--------------------<%
Set XML = server.CreateObject("Microsoft.XMLDOM")
Set SerInfo = XML.createElement("SerInfo")
XML.appendChild SerInfo
Set Result = XML.createElement("client")
SerInfo.appendChild Result
Set sim = XML.createElement("sim")
Result.appendChild sim
set attrib=XML.createAttribute("phone")
attrib.value="phone"
sim.attributes.setNamedItem(attrib)
set attrib=XML.createAttribute("expire")
attrib.va