f=trim(Request("id"))
   biaoti=Request("title")
 ">

以xml文件作为数据库的程序一例

80酷酷网    80kuku.com

  xml|程序|数据|数据库

 

<%... Language=VBScript %>

<!--#include file="config.asp"-->

<%...
   f=trim(Request("id"))
   biaoti=Request("title")
   neirong=Request("neirong")
IF biaoti="" then
     Response.Write "请输入标题"
     Response.End
 end if
 if neirong="" then
     Response.Write "内容不能为空"
     Response.End
 end if
 

    Set xd = Server.CreateObject("msxml2.domdocument") 
    xd.async = false 
    xd.load(server.mappath(xfolder & "/" & tname2))
    if xd.parseError.errorcode<>0 then
        Response.Write("载入xml文件出错!")
        Response.End()
    end if
   
    sql="//" & rootnode & "/"  & snode & "[index=" & f & "]"

    set node2=xd.selectSingleNode(sql)
    node2.childnodes(0).text=biaoti
    xd.save server.mappath(xfolder & "/" & tname2)
   
    set node2=nothing
    set xd=nothing
   
    filen=f & ".xml"
    strSourceFile = Server.MapPath(xfolder & "/" & filen)

   
   
    set xd2=server.CreateObject("msxml2.domdocument")
    xd2.load(strSourceFile)
    if xd2.parseError.errorcode<>0 then
        Response.Write("载入xml文件出错!")
        Response.End()
    end if
   
    xd2.childNodes(1).childNodes(0).childNodes(0).text=biaoti
    xd2.childNodes(1).childNodes(0).childNodes(1).text=neirong
   
    xd2.save strSourceFile
   
    set node2=nothing
    set xd2=nothing
 
 %>

<script language="javascript">...
    window.close();
</script>
xml分为三种,
index.xml保存一个最大的索引 ,相当于一个序列。
flfgcx_list.xml为一个目录,里面保存了所有的信息的索引信息
另一种就是内容xml,每一种法律都有一个文件。文件名为一个数字,当录入当前的法律的时候自动创造的,名字根据index.xml中的数字 + 1 生成。

 

xml文件的如下:

1 . 目录 (flfgcx_list.xml)

<?xml version="1.0" encoding="gb2312"?>
<flfg>
    <flfgcx>
        <name>中华人民共和国宪法</name>
        <index>1</index>
    </flfgcx>
    <flfgcx><name>中华人民共和国工会法</name><index>2</index></flfgcx><flfgcx><name>吉林省实施《中华人民共和国工会法》若干规定</name><index>3</index></flfgcx><flfgcx><name>中华人民共和国劳动法</name><index>4</index></flfgcx><flfgcx><name>中华人民共和国公司法</name><index>5</index></flfgcx><flfgcx><name>中华人民共和国中外合资经营企业法</name><index>6</index></flfgcx><flfgcx><name>中华人民共和国企业劳动争议处理条例 </name><index>7</index></flfgcx><flfgcx><name>中华人民共和国婚姻法</name><index>8</index></flfgcx><flfgcx><name>中华人民共和国妇女权益保障法</name><index>9</index></flfgcx><flfgcx><name>最高人民法院关于适用《中华人民共和国婚姻法》若干问题的解释(一)</name><index>10</index></flfgcx><flfgcx><name>吉林省计划生育条例</name><index>11</index></flfgcx><flfgcx><name>中华人民共和国体育法</name><index>12</index></flfgcx><flfgcx><name>全民健身计划纲要</name><index>13</index></flfgcx><flfgcx><name>职工安康互助合作保险计划</name><index>14</index></flfgcx></flfg>

2  .  一个内容(?.xml  其中?是一个数字)

<?xml version="1.0" encoding="gb2312"?>
<flfg>
    <flfgcx>
        <name>中华人民共和国宪法</name>
        <content>  序 言

    中国是世界上历史最悠久的国家之一。中国各族人民共同创造了光辉灿烂的文化,具有光荣的革命传统。
  一八四○年以后,封建的中国逐渐变成半殖民地、半封建的国家。中国人民为国家独立、民族解放和民主自由进行了前仆后继的英勇奋斗。
  二十世纪,中国发生了翻天覆地的伟大历史变革。
  一九一一年孙中山先生……
</content>
    </flfgcx>
</flfg>
 3 .    索引(index.xml)

<?xml version="1.0" encoding="gb2312"?>
<flfg>
    <index>15</index>
</flfg>

 

此程序包含对法律数据的增删改操作,具体程序如下:

1 .   录入界面(add.asp)

<html>
<%...Response.Write(request("tt"))%>

<!--#include file="config.asp"-->

<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title><%=cname%>录入界面</title>
</head>
<style>...
td{...}{font-size:13;}
</style>
<body>
<table border="1" cellpadding="0" cellspacing="0" align="center" bordercolor="black" width=760 bgcolor="#c4f578" border="0" cellspacing="0" cellpadding="0" width="80%" height="40" align="center">
<tr><td height="40" bgcolor="#ffcc00"><div align="center"><font size="6" color="#ff3300"><%=cname%>录入界面</FONT></DIV></TD></TR></TABLE>
<hr noshade size="1" color="#ff9900">
<p align=left>说明:在每一段的开始的<font color=red>空格</font>必须是<font color=red>全角</font>的空格。否则提交后不能安目前的段落格式显示。
<form  name="name" action="addsubmit.asp" method="post">
<table border="1" cellspacing="0" cellpadding="0" width="80%" height="300" bordercolordark="#f8ffe1" bordercolorlight="#ff9900" align="center">
<tr><td align=center width=70>标题:</TD>

<td> <INPUT 100%" name="biaoti"> </TD></TR>
<!--
<tr><td align=center>文件名:</TD>

<td> <INPUT name="filename"> </TD></TR>-->
<tr><td align="center">内容:</TD>
    <td><TEXTAREA name="neirong" rows=30  cols=73></TEXTAREA></TD>
</TR>

<tr><td colspan="2"> <p align="center"><input type="submit" value="提交"  id=submit1 name=submit1>
<input type="reset" value="全部重新填写"  id=reset1 name=reset1> <input type=button value="关闭" id=button1 name=button1>
</P></TD></TR></TABLE></FORM>
</td></tr></table>
</body>

2 .   录入提交界面 (addsubmit.asp)
<%... Language=VBScript %>

<!--#include file="config.asp"-->

<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
</HEAD>
<BODY>
 <%...
 
 dim biaoti,neirong,filename
 
 biaoti=Request.Form("biaoti")
 'f=request("filename")
 neirong=request("neirong")
 IF biaoti="" then
     Response.Write "请输入标题"
     Response.End
 end if
 if neirong="" then
     Response.Write "内容不能为空"
     Response.End
 end if
 
 set xd2=server.CreateObject("msxml2.domdocument")
 xd2.async = false 
 xd2.load(server.mappath(xfolder & "/" & tname))
     if xd2.parseError.errorcode<>0 then
        Response.Write("载入xml文件出错!")
        Response.End()
    end if
 f=xd2.childNodes(1).childNodes(0).text
 f=clng(f)+1
 xd2.childNodes(1).childNodes(0).text=f
 xd2.save server.mappath(xfolder & "/" & tname)
 set xd2=nothing
 
    filen=f & ".xml"
    strSourceFile = Server.MapPath(xfolder & "/" & filen)
    set fso=server.CreateObject("scripting.filesystemobject")
    if not fso.FileExists(strSourceFile) then
          fso.CreateTextFile strSourceFile
          set fff=fso.GetFile(strSourceFile)
          set mmm=fff.openastextstream(2)
          mmm.write "<?xml version=""1.0"" encoding=""gb2312"" ?>" & vbcrlf & "<" & rootnode & ">" & vbcrlf &  "<" & snode & ">" & vbcrlf & "</" & snode & ">" & vbcrlf & "</" & rootnode & ">"
          set mmm=nothing
          set fff=nothing
    else
          Response.Write("文件名冲突!")
          Response.End      
    end if
    set fso=nothing
    Set xd = Server.CreateObject("msxml2.domdocument") 

    xd.async = false 
    xd.load(server.mappath(xfolder & "/" & tname2))
    if xd.parseError.errorcode<>0 then
        Response.Write("载入xml文件出错!")
        Response.End()
    end if
   
    set et=xd.documentElement    
    set cnode=xd.createElement(snode)
    et.appendchild(cnode)
    set node2=xd.createElement("name")
    node2.text=biaoti
    cnode.appendchild(node2)
    set node2=xd.createElement("index")
    node2.text=f
    cnode.appendchild(node2)
    xd.save server.mappath(xfolder & "/" & tname2)
   
    set cnode=nothing
    set node2=nothing
    set xd=nothing
    set xd=server.CreateObject("msxml2.domdocument")
    xd.load(server.mappath(xfolder & "/" & filen))
    if xd.parseError.errorcode<>0 then
        Response.Write("载入xml文件出错!")
        Response.End()
    end if
    set cnode=xd.selectSingleNode("//" & rootnode & "/" & snode)
    set node2=xd.createElement("name")
    node2.text=biaoti
    cnode.appendchild(node2)
    set node2=xd.createElement("content")
    node2.text=neirong
    cnode.appendchild(node2)
    xd.save server.mappath(xfolder & "/" & filen)
    set node2=nothing
    set cnode=nothing
    set xd=nothing
   
     if err=0 then
           Response.Redirect "add.asp?tt=录入成功!"  
     else
           Response.Redirect "add.asp?tt=录入失败!"  
     end if

 %>
<center><p><!--<span >--><a %>

<!--#include file="config.asp"-->

<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
</HEAD>
<BODY><center><h3><%=cname%>修改界面</h3></center>
<%...
    f=Request.QueryString("f")
    n=Request.QueryString("n")
    filen=f & ".xml"
    strSourceFile = Server.MapPath(xfolder & "/" & filen)
    Set xd = Server.CreateObject("msxml2.domdocument") 

    xd.async = false 
    xd.load(strSourceFile)
    if xd.parseError.errorcode<>0 then
        Response.Write("载入xml文件出错!")
        Response.End()
    end if   
   
    if not xd.hasChildNodes() then
        Response.Write("为找到指定的数据!")
        Response.End
    end if
   %>
   <form action="xiugai_ok.asp" method="post" name="form1" target="_blank">
    <table border="1" cellpadding="0" cellspacing="0" width="500" align="center" bordercolor="black" bgcolor="#c4f578" <input type="hidden" name="id" value="<%=f%>"></td>
     <tr>
        <td width="150">文件名</td>
        <td width="350"><%=filen%></td>
     </tr>
      <tr>
        <td width="150">标题</td>
        <td width="390"><textarea name="title"  rows=10 cols=80><%=xd.childNodes(1).childNodes(0).childNodes(0).text%></textarea></td>
     </tr>
     <tr>
        <td width="150">内容</td>
        <td width="390"><textarea name="neirong"  rows=10 cols=80><%=xd.childNodes(1).childNodes(0).childNodes(1).text%></textarea></td>
     </tr>
     <tr >
        <td colspan="8"><p align="center"><input type="submit" value="提交" name="button1"><input type=button value="关闭" ></p></td>
     </tr>
   </table>
  


</form>
<%...set xd=nothing%>
</BODY>
</HTML>
6  . 修改提交(xiugai_ok.asp)
<%... Language=VBScript %>

<!--#include file="config.asp"-->

<%...
   f=trim(Request("id"))
   biaoti=Request("title")
   neirong=Request("neirong")
IF biaoti="" then
     Response.Write "请输入标题"
     Response.End
 end if
 if neirong="" then
     Response.Write "内容不能为空"
     Response.End
 end if
 

    Set xd = Server.CreateObject("msxml2.domdocument") 
    xd.async = false 
    xd.load(server.mappath(xfolder & "/" & tname2))
    if xd.parseError.errorcode<>0 then
        Response.Write("载入xml文件出错!")
        Response.End()
    end if
   
    sql="//" & rootnode & "/"  & snode & "[index=" & f & "]"

    set node2=xd.selectSingleNode(sql)
    node2.childnodes(0).text=biaoti
    xd.save server.mappath(xfolder & "/" & tname2)
   
    set node2=nothing
    set xd=nothing
   
    filen=f & ".xml"
    strSourceFile = Server.MapPath(xfolder & "/" & filen)

   
   
    set xd2=server.CreateObject("msxml2.domdocument")
    xd2.load(strSourceFile)
    if xd2.parseError.errorcode<>0 then
        Response.Write("载入xml文件出错!")
        Response.End()
    end if
   
    xd2.childNodes(1).childNodes(0).childNodes(0).text=biaoti
    xd2.childNodes(1).childNodes(0).childNodes(1).text=neirong
   
    xd2.save strSourceFile
   
    set node2=nothing
    set xd2=nothing
 
 %>

<script language="javascript">...
    window.close();
</script>
7 .  删除信息 (del.asp)

<%... Language=VBScript %>

<!--#include file="../conn.asp"-->

 <%...
 f=Request("f")
 n=request("n")
 IF f="" or n="" then
     Response.Write "参数故障!"
     Response.End
 end if

    filen=f & ".xml"
    strSourceFile = Server.MapPath(xfolder & "/" & filen)
    set fso=server.CreateObject("scripting.filesystemobject")
    if(fso.FileExists(strSourceFile)) then fso.DeleteFile strSourceFile
    set fso=nothing
   
    Set xd = Server.CreateObject("msxml2.domdocument") 

    xd.async = false 
    xd.load(server.mappath(xfolder & "/" & tname2))
    if xd.parseError.errorcode<>0 then
        Response.Write("载入xml文件出错!")
        Response.End()
    end if
    set et=xd.documentElement    
    sql="//" & rootnode & "/"  & snode & "[name='" & n & "' && index=" & f & "]"
    set node2=xd.selectSingleNode(sql)
   
    et.removeChild(node2)
   
    xd.save server.mappath(xfolder & "/" & tname2)
    
    set node2=nothing
    set xd=nothing
 
     Response.Redirect firstPage  
 
 %>

8  .   维护界面主界面 (default.asp)

<%... Language=VBScript %>

<!--#include file="config.asp"-->

<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
<style>...
  td{...}{font-size:13;word-wrap:break-word}
</style>
</HEAD>

<BODY>

<%...strSourceFile = Server.MapPath(xfolder & "/" & tname2)
    Set xd = Server.CreateObject("msxml2.domdocument") 
    xd.async = false 
    xd.load(strSourceFile)
    if xd.parseError.errorcode<>0 then
        Response.Write("载入xml文件出错!")
        Response.End()
    end if
    'set tnode=xd.childNodes(1)
      
%>
<table border="1" cellpadding="0" cellspacing="0" align="center" bordercolor="black" width="760" bgcolor="#c4f578" align=center colspan="<%=4%>"><%=cname%></td></tr>
<tr height=30><td colspan="<%=4%>" align=left>目前总记录数:<%=xd.childNodes(1).childNodes.length%>    <a CODEPAGE="CP_ACP"%>

<!--#include file="config.asp"-->

<html>
<head>
<title>工会网</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>

<body>
<div align="center"   width=760 <table width="760"  bgcolor="#DEF342" border="0" cellspacing="0" cellpadding="0">
    <tr>
      <td height="22" width="760" colspan="3" background="../images/web040.jpg"> </td>
    </tr>
    <tr>
      <td colspan="3" width="760" height="152"><img src="http://www.pushad.com/images/USET.jpg" width="760" height="150"></td>
    </tr>
    <tr>
      <td height="22" width="760" colspan="3" background="../images/web040.jpg"> </td>  
    </tr>  
    <tr height=4><td colspan=3></td></tr>  
    <tr>   
      <td height="50" width="760" colspan="3">
<table width="760" border="0" cellspacing="0" cellpadding="0" bgcolor="#DEF342">  
          <tr>   
           <td width=760><span > <a href="<%=Mainfolder%>/<%=MainPage%>">长客工会网</a>   
                > <span <tr><td width=760>   
              <table border="0" cellpadding="0" cellspacing="0" width="720" align="center">
<%...
      f=Request.QueryString("f")
      n=Request.QueryString("n")
      f=f & ".xml"
    strSourceFile = Server.MapPath(xfolder & "/" & f)
    Set xd = Server.CreateObject("msxml2.domdocument") 

    xd.async = false 
    xd.load(strSourceFile)
    if xd.parseError.errorcode<>0 then
        Response.Write("载入xml文件出错!")
        Response.End()
    end if   
   
   
%>


<tr><td width="760">
 <p align="center" height=30><b><span width=720 align=left>
<%...
'for i=0 to xd.childNodes(1).childNodes.length-1
if xd.childNodes(1).childNodes.length>0 then
   if xd.childNodes(1).childNodes(0).childNodes.length>0 then
     if xd.childNodes(1).childNodes(i).childNodes(0).text=n then
         cont=xd.childNodes(1).childNodes(i).childNodes(1).text
   
%>
<pre><div align=center><div  align=left><%=cont%> </div>

<p align="center"><a href="<%=Mainfolder%>/<%=MainPage%>"><img src="http://www.pushad.com/images/home.jpg"></a></p>          
<table cellpadding=0 cellspacing=0 width=100% bgcolor=ffffff>
<tr height=3 bgcolor=aaaaaa><td></td></tr>
<tr height=10><td></td></tr>
<tr><td><!--#include file=../config/footer.htm --></td></tr></table>
</div></pre>
<%...    end if
   end if
end if
'next%>     
</td></tr></table> </td></tr>
        </table>
 
        </td>                
    </tr>                
                 
  </table>               
</div>               
</body>               
</html>               

 



分享到
  • 微信分享
  • 新浪微博
  • QQ好友
  • QQ空间
点击: