Using asp+xml to achieve code management actually means using asp to operate xml. The following is the menu.asp code
program code
<%
'---------------------------------------
'Author: weeds
'Date: April 24, 2006
'QQ:94440079
'---------------------------------------
'Read XML file function
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
'Determine whether it is a pop-up window
If menu_open=0 Then
'Determine whether it is the first one, if it is the first one, remove it┊
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
'Output XML menu
response.write(YCMS_menu())
%>
The following is the menu.xml code:
program code
<?xml version=1.0 encoding=gb2312?>
<xml>
<menu>
<url name=Website homepageopen=0>index.asp</url>
<url name=News open=0>News.asp</url>
<url name=Article Centeropen=0>Art.asp</url>
<url name=Picture display open=0>Pic.asp</url>
<url name=AVEntertainmentopen=0>Dj.asp</url>
<url name=resource download open=0>Down.asp</url>
<url name=Leave a message for discussion open=0>Book.asp</url>
<url name=Friendly link open=0>Link.asp</url>
</menu>
</xml>
admin_menu.asp background management XML file part
The following is admin_menu.asp
program code
<%
'Use ADO.Stream component to save files
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='modify' />
</form>
</body>
</html>