Asp.net+xml implementation without database forum is a point of access

Source: Internet
Author: User
Tags chr include variables tag name xsl xsl file xsl stylesheet access database
asp.net|xml| Data | Database Drafting language: Popular forum (we focus on asp,asp. NET forum) Development idea
Veteran can skip this section and attend the next section.

At present, there are countless different versions of online forums, in the final analysis how the avatar its core data access warehouse are "database", I refer to our Common access SQL Server and so on this form of "database", and then by the PHP asp ASP. NET JSP, and so on these background language through the center "Ado,sql" two lines, like logging bypass a small piece of a small piece (member registration, Member login, forum column classification, project statistics, a single column, post browsing, background management ...) Building blocks like a forum system of different forms, and this piece of "building blocks", how strange it is the access to the database is nothing but the composition of the wood will not become iron, can be seen, good forum procedures are not difficult to write, is rare is clear thinking, high-quality "database structure", since this is so, Below I will begin to develop ASP. Net+xml No Database Implementation Forum Summary of some experience ideas one by one statements, read if you are interested may wish to do a try, try to use new means to develop the fun of the forum

Section One: Nonsense, answer questions.

1: This article needs to know what knowledge of the people can read?
At least one year of learning Web Background Web site programming comprehensive knowledge of people can read, familiar with the ASP. NET programming and XML document structure programmers can more deeply understand
Can 2:xml act as a "database"?
Yes, it's just a different concept and organization.
3: Using XML as a database to make a forum for the development of the difficulty is more difficult than using Access, SQL Server, etc. for database development?
Much higher, and even some of the functions of their own level limited to solve (XML as a database compared to access, etc. have a certain intrinsic limitations), but does not mean that it is not possible
4: Why this article choose ASP. NET as a background programming language to combine XML construction forum?
No special meaning, ASP, PHP, JSP or other background program language can be, even VB, VC, Java, etc. can be the form of software Performance forum
5: What are the benefits of XML as a "database" forum or other system compared to the two?
such as program and XML structure is sophisticated, whether in the size of the program system are
-Speed (file-based, relative to ADO Access database)
-Resource consumption (regardless of the sum of the data, basically processing distributed small files (usually within the 1-100k), whether in memory or CPU occupancy, etc. are worried about the database)
-Distributed (a single file is set in a folder, with the advantage of integrating data into a database)
-Portability and versatility (XML itself is a generic data description language that can be successfully ported and applied in different operating systems or program languages)
-Modify, find, maintain, batch processing (such as large amount of data, you must use the program system operations, such as directly in the folder management file is very cumbersome, this is less than the database system interface and ease-of-use, unless the establishment of their own XML data processing software or web systems to make up for this deficiency)
-Security (great wisdom depends on the program, encryption, Smart is to change the background file, folder name and storage location, but based on the XML file structure of the database is rather scattered, as the data Table encapsulation Simple)

Section II: Introduction to the guide, establishment of the base (XML database structure)

Clearly do what kind of forum system, in order to get the idea, here we assume the development of a simple forum, its function is to follow the common forum, we only require a column
Implementation of XML database {
Member data store (create a new file in the home directory, called User.xml, the User.xml file is the file that stores all member information, this example structure is the following form) [
<?xml version= "1.0" encoding= "gb2312"?>
<alluser>
<fyw name= "Dance" pass= "1234" sex= "Men" age= "img=" "User40.jpg" fatie= "exp=" 243 "" homepage= "http://www.lshdic.com" "Email=" lshdic@sina.com "oicq=" 21152530 "qianming=" signature file content "address=" Shandong Linyi "/>
<cike name= "Lone Assassin" pass= "123" sex= "Men" age= "img=" "Man2.gif" fatie= "0" exp= "homepage=" "email=" gdcike@163.com " Oicq= "qianming=" he is a pig! The owner of the customs Zone! "Address=" Shandong Linyi "/>
<plgirl name= "Thousands of pure children" pass= "123" sex= "age=" img= "woman1.gif" fatie= "0" exp= "0" homepage= "" email= "" oicq= "" Qianm " ing= "" address= ""/>
</alluser>
]
This is the XML storage structure used in this example, it is not difficult to see a tag that contains a member of all the information, tag name is "user account", which name= nickname, pass= password, sex= sex ..., where "user account" must be guaranteed to be unique, and must be limited to English letters or letters with a number behind the letter, about the XML file structure and data must conform to the XML document specification and nomenclature, if the user in the program after the submission of data processing is not entrusted, or can lead to data leakage, Or the User.xml is declared scrap, you must manually find the correction, otherwise not normal access

Forum post data Store (in the home directory to create a new folder, named data, the Data folder in the future is to save all members post, in which the file name is random or regular such as 1.xml,2.xml,3.xml, these files store the posts of all the data including themes, replies, Of course, these documents are established, modified, name, delete, etc. are in the future with the program to achieve, as for the new file name of the program to ensure that their names and with a file conflict can be, the file name can be without any regularity, after all, we do not use the filename to achieve sorting, its single XML file content structure as follows) [
1.xml:
<?xml version= "1.0" encoding= "gb2312"?>
<?xml-stylesheet type= ' text/xsl ' href= '. /file.aspx?dex=1.xml '?>
<document>
<record>
<anthor>fyw</anthor>
<title> Post title </title>
<date>2003-12-6 3:27:18</date>
<gengxindate>2003-12-6 3:27:18</gengxindate>
<body> Post Content

</body>
</record>
</document>

2.xml:
<?xml version= "1.0" encoding= "gb2312"?>
<?xml-stylesheet type= ' text/xsl ' href= '. /file.aspx?dex=7908604.xml '?>
<document>
<record>
<anthor>fyw</anthor>
<title> Post title </title>
<date>2003-12-6 3:54:59</date>
<gengxindate>2003-12-6 3:54:59</gengxindate>
<body> Post Content </body>
<reply>
<anthor>cike</anthor>
<date>2003-12-6 5:53:38</date>
<gengxindate>2003-12-6 5:53:38</gengxindate>
Contents of <body>1 reply </body>
</reply>
<reply>
<anthor>plgirl</anthor>
<date>2003-12-7 5:53:38</date>
<gengxindate>2003-12-7 5:53:38</gengxindate>
Contents of <body>2 reply </body>
</reply>
</record>
</document>
]
This is the example forum post XML storage structure, now we have established the member data storage file (user.xml) and forum post storage location and storage structure (data*.xml), you are inspired? Is it really possible to implement a complex forum system with a program that bridges the two cornerstones? The answer is yes, as long as the program in the background to manipulate the two storage base, to be friendly interface, you can try a small
}

Section III: Zhuge Liang, the officers and men sharpening

XML data storage structure to complete, listed below are the materials needed to complete the forum's great Cause
Projects include {
Common function pages
(set up or one or two of these common function pages or DLLs or user controls, put commonly used program procedures, variables, functions into them, use after that can greatly save time to avoid duplication of work, which will be mentioned in the next chapter)

The distinction between visitors and members
(That is, a session, this example is the session ("who") the value of the existence of the judgment, such as the existence of the judge is a member, if there is no value for tourists, we do not use cookies to store user data, visitors are naturally only browsing posts, can not post or reply to posts and the member can)

Member Registration
(contains a variety of forms of the page, the purpose is to complete the Add a new label node to User.xml (equivalent to add a new member data), to deal with the user submitted data, methods to use to prevent cross-station submissions, member accounts (that is, XML node nod tag) To limit the syntax requirements of a program variable to a regular expression or simply allow the use of the English alphabet, XML node properties to filter at least <>& "' and carriage return symbols, prevent the application of the member account to exist User.xml, All data English symbols are converted to lowercase format that is case-insensitive, including user accounts and passwords.

Member Login
(including user account input box, password input box and a login button, submitted using XMLDOM search User.xml whether there is a matching user account (pay special attention to filter the data submitted by users, especially the * number, etc., which in the XMLDOM search is considered a wildcard), If User.xml has the account number, will be a session, this example for the session (the "Who"), set the value of the user account, the identity of the visitors become membership)

Member Data modification
(no visitors are allowed to browse this page. The style remains the same as the form of the Member registration page (but does not include the function of the user account name modification), except that all the form values are read user.xml in the matching session ("who") of the member's information, after the user modified, click to complete the Modify button, At this time, the background program to modify the User.xml of the member corresponding node data can be

Member data show
(Read-only page, read the URL parameters of the corresponding member account, showing the member all need not confidential information)

A Forum Section homepage
(That is, a list of posts, according to the URL page number parameter paging, display the data directory of the corresponding page number of all post information, sorted nature according to the file's modified date, the latest update of the top, this is the most difficult to develop this forum one of the projects, to be careful to deal with, preferably point-to-point (ie 1-10, 30-40,100-110) in the form of paging to extract the files in the data directory, you can ensure the highest quality operating speed.

Post Display page
(This example of the post shows is directly in the browser access to the XML file, that is, http://xxx.xxx.xxx/xxx.xml URL form access, because the only use of static XSL control XML file two-tier output form is not enough, so we take the display structure is three layers, its order is (1: After opening the XML file, look for the XSL file specified by the Xml-stylesheet node's href---2: Because the destination file type is aspx, we access the reference XML file data according to the URL parameter in the target ASPX, control the data flow output format as XSL, The ideal XSL stylesheet is nicely sorted out in the bundle, that plays a key role in the middle tier---3: Because the ASPX output XSL is we in the background, its highly intelligent, reasonable, that is, with the XML data output structure complex post display page), the middle tier of the development of the most difficult, is one of the hardest steps in this forum system, the simple place is the XMLDOM analysis extracts the target XML the node data, realizes the display topic, displays the post author, displays the post content, displays the post all replies, but the most difficult point, I when begins the development, cannot solve the post reply the page, As well as the ASPX server-side control and XSL document specifications conflict, may be my level is limited, or I am original of this 3-tier output is inherently flawed, the so-called XML implementation of the database is easy, but through the XSL to achieve the ideal output beyond the HTML difficult.

Post a new post
(Prohibit visitors to publish, the item is a input of the subject of the input box + content input Box + Submit button, you can bind to the column Post list page or create a new page, the user submitted to use the server after publication.) HTMLEncode () filter the data submitted by the user, then use the program to create the XML file, name the XML file, organize the file format of the XML file, such as the format written in the second section, write filtered data to the node, modify the user.xml corresponding member of the post to achieve points +2 and the number of posts +1, the use of cookies limited to 7 seconds to prohibit multiple submissions of irrigation)

Reply to New post
(no visitors are allowed to reply, this page can be tied to the post display page or a new professional, provide a content input box + Submit button, after submitting such as publishing a new paste process similar to the data filtering, and then in the corresponding post storage XML file inserted a reply node, in the node to store the reply author name, Reply content, reply date, reply update date and so on node, modify user.xml corresponding posting member's node realizes the integral +1 and posts +1, uses the cookie limit 7 seconds to prohibit repeatedly submits the irrigation.

Moderator management function
(To achieve password verification, judge prohibit the use of tourists and members, the optional background management functions have rewards member points, reduce membership points, delete members, modify any posts, delete any posts, and even consider a number of IP, top, lock, moderator, etc. advanced functions)
}

Fourth quarter: King's battle, Kam Sac help

Through the cultivation of the above sections, if you study carefully, you must have a plan, you must have moved hands, or the idea is very clear but do not know how to write procedures, if it is so, do not need urgent noise, the author will be the life of a number of commonly used "Art of War" list, will make you an enlightened

1: Error prompt function (use when needed, pop-up dialog box to the user error reminder, and then automatically returned to the previous page, this function is recommended to save as a general file, when needed <!--#include file= "publicfun.aspx"--> can be used)

<script language=vb runat= ' server ' >
Sub T2 (tstr2 as String)
Response.Write (Replace ("<script language=vbs> MsgBox" & Chr () & TSTR2 & Chr (+) & "," & C HR & "Error alert" & Chr (+) & ": History.back () </script>", "<", "<"): Response.End
End Sub
</script>

2: General Data detection function (modify XML tag attributes recommended use for general testing, as well as user accounts, etc. need more stringent data filtering)

<script language=vb runat= ' server ' >
Sub Jiancha (Requeststr As String) ' This example filters ' <>&*, if there is any omission please fill
Dim array1 (5) As String
Array1 (0) = "'": array1 (1) =chr (): array1 (2) = "<": Array1 (3) = ">": Array1 (4) = "&": Array1 (5) = "*"
Dim tempi As Integer
For tempi=0 to UBound (array1)
If InStr (Requeststr,array1 (tempi)) <>0 Then Response.Write (replace ("<script language=vbs> MsgBox" & CHR & "Reference Data & Requeststr &" Can not contain prohibited symbols ["& Array1 (Tempi) &"], automatically return please correct "& Chr (1) &". 6, "& Chr (+) &" error Tip & Chr & vbCrLf & "History.back () </script>", "<", "<"): Response . end
Next
End Sub
</script>

3:asp.net refuses to cross station submit injection (can be used in more forms such as member registration, Member modification page, etc.)

<%
If LCase (Mid (Request). ServerVariables ("Http_referer"), 8,len (request. ServerVariables ("SERVER_NAME"))) <>lcase (request. ServerVariables ("SERVER_NAME")) then T2 ("Reject cross-station submissions!") ")
%>

4: Add a new node to the destination XML file

<% @import namespace= ' System.Xml '%>
<%
Dim userdom1=new Xmldocument,userdom2,userdom3
Userdom1.load (Server.MapPath ("User.xml")) ' loads the XML file that needs to be manipulated
Userdom2=userdom1.selectsinglenode ("AllUser") ' Action cursor points to alluser node, handle to USERDOM2 variable
Userdom3=userdom1.createelement ("Fyw") ' Creates a new node for Fyw and gives the handle to the USERDOM3 variable
Userdom3.setattribute ("name", "Cloud Dance") "Add node properties for USERDOM3, new property name, value for dance
Userdom3.setattribute ("Pass", "123")
userdom3.innertext= "Test" sets the data contained in the USERDOM3 node
Userdom2. AppendChild (USERDOM3) ' Userdom2 is the AllUser node to add the USERDOM3 node described by Fyw
Userdom1.save (Server.MapPath ("User.xml")) ' saves changed new XML data to User.xml
%>

5: Modifying XML nodes

<% @import namespace= ' System.Xml '%>
<%
Dim userdom1=new Xmldocument,userdom2
Userdom1.load (Server.MapPath ("User.xml"))
Userdom2=userdom1.selectsinglenode ("AllUser"). getElementsByTagName ("Fyw") ' Operation cursor points to alluser node under Fyw node
Userdom2 (0). setattribute ("name", "Dance") ' Set the first of the Fyw node array, modify its Name property value to dance
Userdom2 (0). innertext= "Test" set the first of the Fyw node array, change its contained data to a test
Userdom1.save (Server.MapPath ("User.xml")) ' saves changed new XML data to User.xml
%>

6: Find out if the XML node exists

<% @import namespace= ' System.Xml '%>
<%
Dim userdom1=new XmlDocument
Userdom1.load (Server.MapPath ("User.xml")) ' loads the XML file that needs to be manipulated
The following is why I want to use "user account" to identify the purpose of the user's unique identity, find convenient AH:
If Userdom1.selectsinglenode ("AllUser"). getElementsByTagName ("Fyw"). Count<>0 then ("T2 node exists")
%>

7: Add the XML node in bulk (when writing a reply post, use the method mentioned in the 4th example to fill in a node is very troublesome, then you can consider using this method bulk filling)

<% @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")
' This method is convenient, and the structure of the XML file is also very good, reasonable space and carriage return can be a good performance of the XML document structure
Filedom2.innerxml=vbcrlf & "<anthor>" & Session ("Who") & "</anthor>" & vbCrLf & <dat E> "& Now &" </date> "& vbCrLf &" <gengxindate> "& Now &" </gengxindate> "&A mp 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: Delete XML node

<% @import namespace= ' System.Xml '%>
<%
Dim userdom1=new Xmldocument,userdom2
Userdom1.load (Server.MapPath ("User.xml"))
Userdom1. Documentelement.removechild (Userdom1.selectsinglenode ("Alluser/fyw")) ' Deletes all FYW nodes under AllUser node
Userdom1.save (Server.MapPath ("User.xml"))
%>

9: Create a new XML file (you can create files of any type suffix, not in an XML file)

<% @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)
' Above we specify the default encoding for System.Text.encoding.default, or it can be changed to System.Text.encoding.GetEncoding ("gb2312"), Otherwise, the XML containing Chinese will not work properly with UTF8 encoding.
Newfile.write ("<?xml version=" & Chr (a) & "1.0" & Chr (+) & "encoding=" & Chr (+) & "gb2312" & Chr & "?>" & _
vbCrLf & "<?xml-stylesheet type= ' text/xsl ' href= '". /file.aspx?dex= "& filelength+1 &". Xml '?> ' & vbCrLf & _
"<document>" & vbCrLf & "<record>" & vbCrLf & "<anthor>" & Session ("Who") & "& Lt;/anthor> "& vbCrLf & _
"<title>" & Server. HTMLEncode (biaoti.value) & "</title>" & vbCrLf & "<date>" & Now & "</date>" & V Bcrlf & _
"<gengxindate>" & Now & "</gengxindate>" & vbCrLf & "<body>" & Server. HTMLEncode (Neirong.text) & "</body>" & vbCrLf & _
"</record>" & vbCrLf & "</document>")
Newfile.close:newfile=nothing
%>

10: Delete the specified file

<% @import namespace= ' System.IO '%>
<%file.delete (Server.MapPath ("Data2.xml"))%>

11: Use cookies to achieve 7 seconds not to repeat the irrigation

<%
If not request.cookies ("Lshdicbbs") are nothing Then
If IsDate (Request.Cookies ("Lshdicbbs") ("Guanshui")) =false then ("Response.Cookies") ("Lshdicbbs") Guanshui
If DateDiff ("s", Request.Cookies ("Lshdicbbs") ("Guanshui"), now <7 then ("No repeat post irrigation in 7 Seconds"): Response.Cookies ("Lshdicbbs") ("Guanshui") =now:response.end
End If
Response.Cookies ("Lshdicbbs") ("Guanshui") =now
%>

12: Using regular expressions to limit the user submitted data must be English letters (with interest can be extended to support the form of letters + numbers)

<%
Dim Name1=request.form ("username")
If Regex.Replace (name1, "[a-z]+", "", Regexoptions.ignorecase) <> "" Then T2 ("account name must use A-za-z range of English letters")
%>

13: Extended Hint Tool (previous original script, can be modified as needed)

<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;p adding:2;white-space: nowrap;table-layout:fixed; ' id=showdiv></div>
<script>
var oldtext= "Acceleration Variables", 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= ' Welcome to the author website ' > Lanli net </a>
<a href= "Http://www.lshdic.com/bbs" lshdic= ' Welcome to Lanli Technical Forum 2003-12-6 10:31:32 ' > Lanli Technology Forum </a>

Fifth verse: God sword here, give me bosom friend

After a hard study of the 4 chapters, I believe that you have a basic understanding of how to use the background program with XML database to achieve complex forums and systems, but read through the n Edge also can not play a practical role, you have to go to do, in order to summarize their experience in practice, this article is only a supplementary reference


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.