ASP XML制作菜單管理程序
更新時間:2008年12月29日 20:52:13 作者:
利用asp+xml實現(xiàn)代碼管理,實際就是利用asp操作xml
以下是menu.asp代碼
程序代碼
<%
'---------------------------------------
'作者:野 草
'日期:2006年4月24日
'Q Q:94440079
'---------------------------------------
'讀取XML文件函數(shù)
Function YCMS_menu()
dim menu_temp,m
Set goxml=Server.CreateObject("Microsoft.XMLDOM")
goxml.load(Server.MapPath("menu.xml"))
Set goroot=goxml.documentElement.selectSingleNode("menu")
m=0
For each child in goroot.childNodes
set childmenu=goroot.childnodes.item(m)
Dim menu_open,menu_title,menu_url
menu_open=childmenu.getAttributeNode("open").nodeValue
menu_name=childmenu.getAttributeNode("name").nodeValue
menu_url=goroot.childNodes.item(m).text
'判斷是否是彈出窗口
If menu_open=0 Then
'判斷是否是第一個,若是第一個則去掉"┊"
If m=0 Then
menu_temp=menu_temp&"<a href='"&menu_url&"'>"&menu_name&"</a>"
Else
menu_temp=menu_temp&"┊<a href='"&menu_url&"'>"&menu_name&"</a>"
End If
Else
If m=0 Then
menu_temp=menu_temp&"<a href='"&menu_url&"' target='o'>"&menu_name&"</a>"
Else
menu_temp=menu_temp&"┊<a href='"&menu_url&"' target='o'>"&menu_name&"</a>"
End If
End If
set childmenu=nothing
m=m+1
next
set goroot=nothing
set goxml=nothing
YCMS_menu=menu_temp
End Function
'輸出XML菜單
response.write(YCMS_menu())
%>
以下是menu.xml代碼:
程序代碼
<?xml version="1.0" encoding="gb2312"?>
<xml>
<menu>
<url name="網(wǎng)站首頁" open="0">index.asp</url>
<url name="新聞動態(tài)" open="0">News.asp</url>
<url name="文章中心" open="0">Art.asp</url>
<url name="圖片展示" open="0">Pic.asp</url>
<url name="影音娛樂" open="0">Dj.asp</url>
<url name="資源下載" open="0">Down.asp</url>
<url name="留言討論" open="0">Book.asp</url>
<url name="友情連接" open="0">Link.asp</url>
</menu>
</xml>
admin_menu.asp 后臺管理XML文件部分
以下是admin_menu.asp
程序代碼
<%
'利用ADO.Stream組件保存文件
Function Save(file_body,file_name)
Set OS=Server.CreateObject("ADODB.Stream")
OS.Type=2
OS.Open
OS.Charset="GB2312"
OS.Position=OS.Size
OS.WriteText=file_body
OS.SaveToFile Server.MapPath(file_name),2
OS.Close
Set OS=Nothing
End Function
if Request.QueryString("action")="ok" then
call Save(Request.Form("content"),"menu.xml")
end if
%>
<html>
<head>
<title></title>
</head>
<body>
<form action="?action=ok" method="post">
<textarea style='width:500px;height:200px;' name='content'>
<%=server.execute("menu.xml")%>
</textarea>
<input type='submit' value='修 改' />
</form>
</body>
</html>
程序代碼
<%
'---------------------------------------
'作者:野 草
'日期:2006年4月24日
'Q Q:94440079
'---------------------------------------
'讀取XML文件函數(shù)
Function YCMS_menu()
dim menu_temp,m
Set goxml=Server.CreateObject("Microsoft.XMLDOM")
goxml.load(Server.MapPath("menu.xml"))
Set goroot=goxml.documentElement.selectSingleNode("menu")
m=0
For each child in goroot.childNodes
set childmenu=goroot.childnodes.item(m)
Dim menu_open,menu_title,menu_url
menu_open=childmenu.getAttributeNode("open").nodeValue
menu_name=childmenu.getAttributeNode("name").nodeValue
menu_url=goroot.childNodes.item(m).text
'判斷是否是彈出窗口
If menu_open=0 Then
'判斷是否是第一個,若是第一個則去掉"┊"
If m=0 Then
menu_temp=menu_temp&"<a href='"&menu_url&"'>"&menu_name&"</a>"
Else
menu_temp=menu_temp&"┊<a href='"&menu_url&"'>"&menu_name&"</a>"
End If
Else
If m=0 Then
menu_temp=menu_temp&"<a href='"&menu_url&"' target='o'>"&menu_name&"</a>"
Else
menu_temp=menu_temp&"┊<a href='"&menu_url&"' target='o'>"&menu_name&"</a>"
End If
End If
set childmenu=nothing
m=m+1
next
set goroot=nothing
set goxml=nothing
YCMS_menu=menu_temp
End Function
'輸出XML菜單
response.write(YCMS_menu())
%>
以下是menu.xml代碼:
程序代碼
<?xml version="1.0" encoding="gb2312"?>
<xml>
<menu>
<url name="網(wǎng)站首頁" open="0">index.asp</url>
<url name="新聞動態(tài)" open="0">News.asp</url>
<url name="文章中心" open="0">Art.asp</url>
<url name="圖片展示" open="0">Pic.asp</url>
<url name="影音娛樂" open="0">Dj.asp</url>
<url name="資源下載" open="0">Down.asp</url>
<url name="留言討論" open="0">Book.asp</url>
<url name="友情連接" open="0">Link.asp</url>
</menu>
</xml>
admin_menu.asp 后臺管理XML文件部分
以下是admin_menu.asp
程序代碼
<%
'利用ADO.Stream組件保存文件
Function Save(file_body,file_name)
Set OS=Server.CreateObject("ADODB.Stream")
OS.Type=2
OS.Open
OS.Charset="GB2312"
OS.Position=OS.Size
OS.WriteText=file_body
OS.SaveToFile Server.MapPath(file_name),2
OS.Close
Set OS=Nothing
End Function
if Request.QueryString("action")="ok" then
call Save(Request.Form("content"),"menu.xml")
end if
%>
<html>
<head>
<title></title>
</head>
<body>
<form action="?action=ok" method="post">
<textarea style='width:500px;height:200px;' name='content'>
<%=server.execute("menu.xml")%>
</textarea>
<input type='submit' value='修 改' />
</form>
</body>
</html>
相關文章
asp之自動閉合HTML/ubb標簽函數(shù)附簡單注釋
這樣的功能就是實現(xiàn)一般html,ubb標簽的閉合,以前在pjblog中見過,一直沒用,這個函數(shù)不錯,建議可以參考下pjblog中的函數(shù)。2009-01-01ASP基礎入門第四篇(腳本變量、函數(shù)、過程和條件語句)
大家在學習了腳本語言 VBScript 的變量、常量和過程的基本概念后,本期將繼續(xù)向各位介紹 VBScript 的函數(shù)和語法。2015-10-10通過ASP禁止指定IP和只允許指定IP訪問網(wǎng)站的代碼
通過ASP禁止指定IP和只允許指定IP訪問網(wǎng)站的代碼,需要的朋友可以參考下。2011-10-10談動態(tài)多行多列,循環(huán)行和列,輸出M行N列的ASP代碼
2008-03-03