原XML文件;
<?xml version="1.0" encoding="utf-8" ?> <dataroot> <news> <new> <title>新闻标题1</title> <shortdesc><![CDATA[sinker.cn flash片]]></shortdesc> <date>1</date> <link>http://www.sinker.cn</link> </new> <new> <title>新闻标题2</title> <shortdesc><![CDATA[sinker.cn flash片]]></shortdesc> <date>1</date> <link>http://www.sinker.cn</link> </new> </news> </dataroot>
下面是我做的生成像上面那个XML内容的xml.asp文件,代码如下:
<% @language="VBScript" @codepage="65001"%> <% Option Explicit Response.contentType="news/xml" dim conn,connstr,rs,sql connstr="provider=Microsoft.Jet.OLEDB.4.0;data source="&Server.MapPath("Data-2007/sou596#zuoyun.mdb")&";" set conn=Server.CreateObject("ADODB.Connection") set rs=Server.CreateObject("ADODB.RecordSet") conn.open connstr sql="select top 6 * from news order by ID desc" rs.open sql,conn,1,1 Response.Write("<?xml version='1.0' encoding='utf-8'?><dataroot><news>") %> <% do while not rs.eof Response.Write("<new><title>"&rs("Title")&"</title><shortdesc><![CDATA[123]]></shortdesc><date>"&rs("AddDate")&"</date><link>shownews.asp?ID="&rs("ID")&"</link></new>") rs.movenext loop %> <% Response.Write("</news></dataroot>") rs.close conn.close set rs=nothing %>