CSDN博客

img fly29

利用ASP+XML自动生成静态HTM

发表于2004/9/16 10:47:00  1640人阅读

分类: web开发

昨晚花了两个小时时间做了一个小例子。功能:接收表单传值生成临时XML文件,结合XSL,生成静态HTML文件。

<!--process.asp
用于生成临时XML文件,并生成静态HTML文件
-->

<!--#include file="conn.inc"-->
<%
author=request.form("n_author")
title=request.form("n_title")
content=request.form("n_content")

tempXml=replace( replace( replace (now,":",""), "-", ""), " ", "") & ".xml"
dim objdom
set objdom=server.createobject("Microsoft.XMLDOM")
dim objroot
set objroot=objdom.createElement("moonpiazza")
objdom.appendchild objroot

Set objPI = objDom.createProcessingInstruction("xml","version='1.0'")
objDom.insertBefore objPI, objDom.childNodes(0)

dim objbook
set objbook=objdom.createElement("book")
objroot.appendchild objbook

set objtit=objdom.createElement("书名")
objtit.text=title
objbook.appendchild objtit

set objaut=objdom.createElement("作者")
objaut.text=author
objbook.appendchild objaut

set objpri=objdom.createElement("定价")
objpri.text=content
objbook.appendchild objpri

'生成临时XML放于TEMP文件夹下

objdom.save(server.mappath("temp/"&tempXml))

'//以下部分为生成htm部分
cHtmLFile = replace( replace( replace (now,":",""), "-", ""), " ", "") & ".htm"

cXMLFile =server.mappath("temp/"&tempXml)
cXSLFile = Server.MapPath("book.xsl")
cOutputFile = Server.MapPath("news/"&cHtmLFile)

Set oXML = Server.CreateObject("Microsoft.XMLDOM")
oXML.async = false
oXML.load(cXMLFile)

Set oXSL = Server.CreateObject("Microsoft.XMLDOM")
oXSL.async = false
oXSL.load(cXSLFile)

Set oOutput = Server.CreateObject("Microsoft.XMLDOM")
Call oXML.transformNodeToObject(oXSL, oOutput)

oOutput.save (cOutputFile)

Set oXML = Nothing
Set oXSL = Nothing
Set oOutput = Nothing

sql="INSERT INTO news(author,title,content,url) values('"&author&"','"&title&"','"&content&"','news/"&cHtmLFile&"')"

conn.execute(sql)

'生成HTM文件保存到NEWS文件夹下

Response.redirect("news/"&cHtmLFile)

%>

<!--list.asp

文件列表-->

<!--#include file="conn.inc"-->
<%response.contentType="text/html"%>
<html>
<body>
<%
response.write("<table>")
set rs=server.createobject("adodb.recordset")
rs.open "select * from news ",conn,1,1
do while not rs.eof
 response.write("<tr><td><a href="&rs("url")&" target='_blank'>"&rs("title")&"</a></td></tr>")
rs.movenext
loop
response.write("</table>")
%>

0 0

相关博文

我的热门文章

img
取 消
img