asp操作xml的问题
- XML code
<?xml version="1.0"?> <Banner bannerWidth="310" bannerHeight="116" textSize="14" textColor="" textAreaWidth="" textLineSpacing="0" textLetterSpacing="-0.5" textMarginLeft="12" textMarginBottom="3" transitionType="1" transitionDelayTimeFixed="2.5" transitionDelayTimePerWord=".5" transitionSpeed="8" transitionBlur="yes" transitionRandomizeOrder="no" showTimerClock="yes" showBackButton="yes" showNumberButtons="yes" showNumberButtonsAlways="Yes" showNumberButtonsHorizontal="yes" showNumberButtonsAscending="yes" autoPlay="yes"> <item image="../images/b1.jpg" link="#" textBlend="no"><![CDATA[]]></item> <item image="../images/b2.jpg" link="#" textBlend="no"><![CDATA[]]></item> <item image="../images/b3.jpg" link="#" textBlend="no"><![CDATA[]]></item> <item image="../images/b4.jpg" link="#" textBlend="no"><![CDATA[]]></item> <item image="../images/b5.jpg" link="#" textBlend="no"><![CDATA[]]></item> </Banner>我想用程序 从db读取生成item列表,如何实现?
[解决办法]
<!--#include file="M_conn.asp"-->
<%
username=request("username")
set rshot=server.CreateObject("adodb.recordset")
sql="select * from TZ_all where username='"&username&"' order by id desc"
rshot.open sql,conn,1,1
if not (rshot.eof and rshot.bof) then
i=0
do while not rshot.eof
line=line&" <value xid="""&i&""">"&rshot("rl_time")&"</value>"&vbcrlf&""
line2=line2&" <value xid="""&i&""">"&rshot("rl")&"</value>"&vbcrlf&""
i=i+1
rshot.movenext
loop
end if
rshot.close
set rshot=nothing
xmlfile=server.mappath("/party/amline/value_indicator/amline_rl_"&username&".xml")
Set fso = CreateObject("Scripting.FileSystemObject")
Set MyFile = fso.CreateTextFile(xmlfile,True)
MyFile.WriteLine("<?xml version=""1.0"" encoding=""UTF-8""?>")
MyFile.WriteLine("<chart>")
MyFile.WriteLine(" <series>")
MyFile.WriteLine line
MyFile.WriteLine(" </series>")
MyFile.WriteLine(" <graphs>")
MyFile.WriteLine(" <graph gid=""1"">")
MyFile.WriteLine line2
MyFile.WriteLine(" </graph>")
MyFile.WriteLine(" </graphs>")
MyFile.WriteLine("</chart>")
MyFile.Close
response.Redirect("m_my_bar.asp?username="&username&"")
%>
<%
xmlfile=server.mappath("test1.xml")
Set fso = CreateObject("Scripting.FileSystemObject")
Set MyFile = fso.CreateTextFile(xmlfile,True)
MyFile.WriteLine("<?xml version=""1.0"" encoding=""UTF-8""?>")
MyFile.WriteLine("<chart>")
MyFile.WriteLine(" <series>")
MyFile.WriteLine(" <value xid=""0"">1997</value>")
MyFile.WriteLine(" <value xid=""1"">1997</value>")
MyFile.WriteLine(" </series>")
MyFile.WriteLine(" <graphs>")
MyFile.WriteLine(" <graph gid=""1"">")
MyFile.WriteLine(" <value xid=""0"">50</value>")
MyFile.WriteLine(" <value xid=""1"">50</value>")
MyFile.WriteLine(" </graph>")
MyFile.WriteLine(" </graphs>")
MyFile.WriteLine("</chart>")
MyFile.Close
%>
<a href="test1.xml">查看XML文件内容</a>
[解决办法]
- VBScript code
<%sSourcePath = "xxx.xml"Set oDoc = CreateObject("Msxml2.DOMDocument")With oDoc .async = False .validateOnParse = False .preserveWhiteSpace = False .resolveExternals = False .setProperty "NewParser", True .load sSourcePath If .parseError.errorCode <> 0 Then sErrMsg = .parseError.errorCode & "|" &_ .parseError.srcText & "|" & .parseError.reason Response.Write sErrMsg Response.End End IfEnd WithSet oNodes = oDoc.selectNodes("//item")oNodes.removeAll' open conn ...' sql = "....."Set rs = CreateObject("ADODB.RecordSet")rs.CursorLocation = 3rs.Open sql, conn, 1, 1Do While Not rs.EOF Set oNode = oDoc.createElement("item") oNode.setAttribute "image", rs("image").Value oNode.setAttribute "link", "#" oNode.setAttribute "textBlend", "no" Set oCDATA = oDoc.createCDATASection(rs("cdata").Value) oNode.appendChild oCDATA oDoc.documentElement.appendChild oNode Set oNode = Nothing Set oCDATA = Nothing rs.MoveNextLooprs.CloseSet rs = Nothingconn.CloseSet conn = NothingoDoc.save oDoc.urlSet oDoc = Nothing%>