目前很多网站系统都使用了模板管理功能,基本上都是把模板HTML文件装载到了数据库里!
好了!现在我来写个用XML文件存放模板的吧!道理都一样哦!
第一部:建立XML文件skin.xml
| 引用: |
[table border="1" cellspacing="0" cellpadding="0" width="100%"] [tr] [td] 现在的时间是:$now$ [/td] [/tr] [/table]
| |
第二部:建立ASP文件skin.ASP
| 引用: |
<% '初始化变量 dim YCM,child,skin '建立XML对象 set YCMS=Server.CreateObject("Microsoft.XMLDOM") '创建属性是否独立使用的 YCMS.async=false '载入在服务器上的XML文件 YCMS.load(server.mappath("skin.xml")) '建立XML文档元素对象 set go=YCMS.DocumentElement '开始替换XML文件中的字符 skin=replace(go.childNodes.item(0).text,"[","<") skin=replace(skin,"]",">") skin=replace(skin,"$now$",now()) '输出HTML模板代码并执行 response.write ""&skin&"" set go=nothing set YCMS=nothing %> | |
<