转至繁体中文版     | 网站首页 | 图文教程 | 资源下载 | 站长博客 | 图片素材 | 武汉seo | 武汉网站优化 | 
最新公告:     敏韬网|教学资源学习资料永久免费分享站!  [mintao  2008年9月2日]        
您现在的位置: 学习笔记 >> 图文教程 >> 站长学院 >> Web开发 >> 正文
Asp.net+Xml实现无数据库论坛一点即通         ★★★★

Asp.net+Xml实现无数据库论坛一点即通

作者:闵涛 文章来源:闵涛的学习笔记 点击数:1148 更新时间:2009/4/23 10:49:23
sp;    ''''设置userdom3节点所包含的数据
userdom2.AppendChild(userdom3)                      ''''userdom2即alluser节点下添加userdom3所描述的fyw节点
userdom1.save (server.mappath("user.xml"))          ''''将变动后的新XML数据保存到user.xml
%>

5:修改XML节点

<%@import namespace=''''system.xml''''%>
<%
dim userdom1=new xmldocument,userdom2
userdom1.load (server.mappath("user.xml"))
userdom2=userdom1.selectsinglenode("alluser").getElementsBytagname("fyw")  ''''操作游标指向alluser节点下的fyw节点
userdom2(0).setAttribute("name","风云舞")           ''''设定fyw节点数组的第一个,将其name属性值修改为风云舞
userdom2(0).innerText="测试"                        ''''设定fyw节点数组的第一个,将其所包含的数据改为测试
userdom1.save (server.mappath("user.xml"))          ''''将变动后的新XML数据保存到user.xml
%>

6:查找判断XML节点是否存在

<%@import namespace=''''system.xml''''%>
<%
dim userdom1=new xmldocument
userdom1.load (server.mappath("user.xml"))          ''''装载需要操作的XML文件
''''以下正是本人为什么要用“用户帐号”标识用户唯一身份的目的,查找方便呀:)
if userdom1.selectsinglenode("alluser").getElementsBytagname("fyw").count<>0 then t2("fyw节点以存在")
%>

7:批量添加XML节点(在编写回复帖子时,用第4例提到的方法一个一个填加节点很麻烦,这时可以考虑用此方法批量填加)

<%@import namespace=''''system.xml''''%>
<%
dim filedom=new xmldocument,filedom2
filedom.load(server.mappath("data\" & request.querystring("dex")))  ''''request.querystring("dex")=6.xml
filedom2=filedom.createElement("reply")
''''以下这种方法很方便,而且对XML文件的结构排版也很好,合理的空格和回车可以表现良好的XML文档结构
filedom2.innerXml=vbcrlf & "      <anthor>" & session("who") & "</anthor>" & vbcrlf & "      <date>" & now & "</date>" & vbcrlf & "      <gengxindate>" & now & "</gengxindate>" & vbcrlf & "      <body>" & neirong.value & "</body>" & vbcrlf & "      "
filedom.selectsinglenode("document/record").appendChild(filedom2)
filedom.save(server.mappath("data\" & request.querystring("dex")))  ''''request.querystring("dex")=6.xml
%>

8:删除XML节点

<%@import namespace=''''system.xml''''%>
<%
dim userdom1=new xmldocument,userdom2
userdom1.load (server.mappath("user.xml"))
userdom1.DocumentElement.RemoveChild (userdom1.selectsinglenode("alluser/fyw"))  ''''删除alluser节点下的所有fyw节点
userdom1.save (server.mappath("user.xml"))
%>

9:创建新的XML文件(可以创建任何类型后缀的文件,不局于XML文件)

<%@import namespace=''''system.io''''%>
<%
dim newfile=new StreamWriter(server.mappath("data\" & new DirectoryInfo(server.mappath("data")).getfiles().length+1 & ".xml"),false,System.Text.Encoding.Default)
''''以上我们指定默认编码方式为System.Text.encoding.default,或者可改为System.Text.encoding.GetEncoding("gb2312"),不然将以UTF8编码那样XML含有中文就无法正常工作了
newfile.write ("<?xml version=" & chr(34) & "1.0" & chr(34) & " encoding=" & chr(34) & "gb2312" & chr(34) & "?>" & _
vbcrlf & "<?xml-stylesheet type=''''text/xsl'''' href=''''../file.aspx?dex=" & filelength+1 & ".xml''''?>" & vbcrlf & _
"<document>" & vbcrlf & "   <record>" & vbcrlf & "   <anthor>" & session("who") & "</anthor>" & vbcrlf & _
"   <title>" & server.HTMLEncode(biaoti.value) & "</title>" & vbcrlf & "   <date>" & now & "</date>" & vbcrlf & _
"   <gengxindate>" & now & "</gengxindate>" & vbcrlf & "   <body>" & server.HTMLEncode(neirong.text) & "</body>" & vbcrlf & _
"   </record>" & vbcrlf & "</document>")
newfile.close:newfile=nothing
%>

10:删除指定文件

<%@import namespace=''''system.io''''%>
<%file.delete(server.mappath("data\2.xml"))%>

11:用cookies实现7秒内不许重复灌水

<%
if not request.cookies("lshdicbbs") is nothing then
if isdate(request.cookies("lshdicbbs")("guanshui"))=false then response.cookies("lshdicbbs")("guanshui")=now
if datediff("s",request.cookies("lshdicbbs")("guanshui"),now)<7 then response.write ("7秒内禁止重复发贴灌水"):response.cookies("lshdicbbs")("guanshui")=now:response.end
end if
response.cookies("lshdicbbs")("guanshui")=now
%>

12:用正则表达式限制用户提交的数据必须为英文字母(有兴趣可延伸强化为支持英文字母+数字的形式)

<%
dim name1=request.form("username")
if regex.replace(name1,"[a-z]+","",RegexOptions.IgnoreCase)<>"" then t2("帐号名必须使用A-Za-z范围的英文字母")
%>

13:扩展提示工具(早先原创脚本,可根据需要修改)

<div style=''''position:absolute;left:0;top:0;border-bottom:1 solid green;border-right:1 solid green;border-left:1 solid cccccc;border-top:1 solid cccccc;display:none;z-index:500;background-color:#FFF7FF;padding:2;white-Space:nowrap;table-Layout:fixed;'''' id=showdiv></div>
<script>
var oldtext="加速变量",colors1=new Array("#FFECD5","#FFF7FF","#FFFFEB","white","#F5FFEB","#EEFAFF","#FFFFEE","#EDFFFC")
function document.onmousemove(){
try{
if(event.srcElement.getAttribute(''''lshdic''''))
{
showdiv.style.left=event.x-3;showdiv.style.top=event.y+document.body.scrollTop+18;if(event.srcElement.lshdic!=oldtext){oldtext=event.srcElement.lshdic;showdiv.innerText=oldtext;showdiv.style.backgroundColor=colors1[Math.round(Math.random()*colors1.length)]};if(showdiv.style.display==''''none'''')showdiv.style.display=''''''''
}else{if(showdiv.style.display=='''''''')showdiv.style.display=''''none'''';}}catch(e){}
}
</script>
<a href="http://www.lshdic.com" lshdic=''''欢迎访问作者网站''''>蓝丽网</a>
<a href="http://www.lshdic.com/bbs" lshdic=''''欢迎访问蓝丽技术论坛&#13;&#13;2003-12-6 10:31:32''''>蓝丽技术论坛</a>

第五节:神剑在此、赠我知音

经过以上4个章节的艰苦学习,我相信您以基本了解了如何用后台程序结合XML数据库实现复杂的论坛和系统,但通读N边也起不了实际作用,你必须着手去做,才能在实践中总结出自己的经验,本文章仅仅是个辅助参考而已

由于时间有限,本人只能将亲手开发的ASP。NET版本的XML无数据库论坛(全称:蓝丽NetXml无数据库论坛1.0)奉献给各位研究,由于本人的ASP。NET虚拟空间有点问题,无法提供在线演示,现仅提供全部原代码下载(以上13例原代码多数采摘于本系统中),地址:http://www.lshdic.com/download/netxmlbbs.rar,下载后可参考帮助文件,在您自己的ASP。NET服务器上测试。

上一页  [1] [2] 


[C语言系列]NET 中C#的switch语句的语法  [Web开发]XML与HTML在语法上的主要区别详解
[系统软件]托拽Explore中的文件到VB.net的窗口  [系统软件]如何让Expat支持中文XML
[系统软件]Boost库在XP+Visual C++.net中的安装  [常用软件]新配色面板:Paint.Net3.0RC1官方下载
[常用软件]用内建的“Net Meeting”聊天  [VB.NET程序]Henry的VB.NET之旅(三)—共享成员
[VB.NET程序]Henry的VB.NET之旅(二)—构造与析构  [VB.NET程序]Henry的VB.NET之旅(一)—失踪的窗体
教程录入:mintao    责任编辑:mintao 
  • 上一篇教程:

  • 下一篇教程:
  • 【字体: 】【发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口
      注:本站部分文章源于互联网,版权归原作者所有!如有侵权,请原作者与本站联系,本站将立即删除! 本站文章除特别注明外均可转载,但需注明出处! [MinTao学以致用网]
      网友评论:(只显示最新10条。评论内容只代表网友观点,与本站立场无关!)

    同类栏目
    · Web开发  · 网页制作
    · 平面设计  · 网站运营
    · 网站推广  · 搜索优化
    · 建站心得  · 站长故事
    · 互联动态
    更多内容
    热门推荐 更多内容
  • 没有教程
  • 赞助链接
    更多内容
    闵涛博文 更多关于武汉SEO的内容
    500 - 内部服务器错误。

    500 - 内部服务器错误。

    您查找的资源存在问题,因而无法显示。

    | 设为首页 |加入收藏 | 联系站长 | 友情链接 | 版权申明 | 广告服务
    MinTao学以致用网

    Copyright @ 2007-2012 敏韬网(敏而好学,文韬武略--MinTao.Net)(学习笔记) Inc All Rights Reserved.
    闵涛 投放广告、内容合作请Q我! E_mail:admin@mintao.net(欢迎提供学习资源)

    站长:MinTao ICP备案号:鄂ICP备11006601号-18

    闵涛站盟:医药大全-武穴网A打造BCD……
    咸宁网络警察报警平台