Use XML to combine the database to lighten the server.

Source: Internet
Author: User
Tags ftp trim client
Today, the database has become the soul of the site, it can be said that the data is not centrally managed
Even if it's not a real website. and ASP plus database, has become mainstream in the mainstream, the site's user login,
Forum, the message has become their use, formerly used in 51 of documents can be done, now use 2 files can be
, but ASP plus the database, but not perfect, especially with the server for frequent interaction.

For example, according to the asp+ database scheme, we can completely reduce the work of the dedicated webmaster to two files: a
A database file that records all the chapters of a novel; another ASP file to read the contents of the database;
Click on the "next chapter" to browse the next chapter ... Indeed, it may seem intuitive and convenient, but it is not dependent on
Is that every time we browse the next chapter, our browser automatically accesses the database in a conscious way because
This, when a visitor has patiently read the novel, our database has been in close contact with it 49 times.
What if you had n 49 times at the same time? Who can guarantee that his server will still be able to handle all requests calmly? Especially a
Some provide search data, the pages of the page to display the site, the server overwhelmed the phenomenon should be more attention, because the query
The result has n pages, which means that visitors can browse through all the results and need to connect to the server to play N times.

If now you say "n times n times, I do not care", then you should immediately click on the mouse browser "back"
Because I'm going to talk about some junk stuff. Of course, if you also want your database program to turn into "N Page records,
An interaction ", please continue to watch, we will explore the integration of XML and database application.

In fact, XML is not as much a reputation as many people think, but no practical use. I don't know if you're thinking the same thing, but
It's a fact that it's hard to see some Web sites that actually have XML applications on the Web. Now, I'm going to list a few unique XML
Now the case, hope to be able to prove the practical and powerful XML:

1.1 XML files + 1 normal HTML files = 49 chapters of novel chapters show
For ordinary home page spaces that do not support ASP, in which case the XML is completely in place of the data
Library, it is very classic to achieve the separation of data and typesetting. XML is completely divided with HTML.

2.1 XML files + 1 to n ASP files = Message book/forum
For ASP home pages that have disabled file component FileSystemObject and Database components
, without file access and database, with XML can also do the message and forum, and realize the number
According to all the functions of the library.
(I published in this forum "the Third Way-----xml-based ASP Message Board", detailed
To illustrate this technology, if you are interested, you can search for this article in the Forum. )

3.1 databases + 1 ASP files embedded in XML = "N page records, one interaction"

It can be said that these several technologies are embodied in the essence of XML. In particular, the 2nd technology, XML has fully demonstrated its own advantages-
Both the powerful database and the lightweight text file (a. mdb file with hundred K, and an. xml file only a few k, and
Database file modification to rely on specialized software or corresponding ASP program, but XML file, notepad enough. ) is even more prosperous.
The exciting is that XML can completely throw away the file access components and database components to achieve data write read, or even new files.
And we are going to talk about "N page records, one interaction" is more XML on the database beyond the overall.

Look at the following XML file first:

<?xml version= "1.0" encoding= "gb2312"?>
< online play >
< songs >
< song name >hello goodbye</song name >
<URL>ftp://61.139.37.148/music/songs01/english/beatles/hellogoodbye.mp3</URL>
< singer >the beatles</singer >
< lyrics >you Say yes, I say no</lyrics >
</Song >
< songs >
< song name >yesterday</>
<URL>http://www.mayia.com/beatlescom/beatles/mp3/mp3/yesterday.mp3</URL>
< singer >the beatles</singer >
< lyrics >yesterday, all I troubles seemed so far away</lyrics >
</Song >
</Online Play >
Try it, edit the file with Notepad, save the file name Songlist.xml, and then open it in IE browser
This file, if there is no syntax error, can display a tree-like page in the browser that is unique to the XML.
Click on the link below to view the effect: XML file

This is a legitimate XML document, and the rules and formatting of XML documents are also very free, if you want to create a new XML
file, simply write the first line of "<?xml version=" 1.0 "encoding=" gb2312 "?>", and the back
The text between the label and the label can be very casual, just observe the following rules:

1. The first label and the tail label must correspond, can repeat, but can not nest.
2. The naming rules for labels are similar to the variable naming rules for programming languages such as java/c/c++, which are case-sensitive.
3. A document can have only one root element, such as "< online play >" In an instance
4. The only keyword "XML", the label cannot begin with these three letters.
5. If there is a conflict between the document and the rule, the Guide XML document will not display correctly in the browser, and it also represents an illegitimate XML
Document.

OK, we already know how to write a legitimate XML document, and next we'll start to explore embedding XML files into HTML
File and manipulate the data in the XML document with the VBScript scripting language. Look at the following file:


<title> embedding html</title> with XML
<body bgcolor= "#000000" text= "#FFFFFF" >

<xml id = "XmlFile" >
< online play >
< songs >
< song name >hello goodbye</song name >
<URL>ftp://61.139.37.148/music/songs01/english/beatles/hellogoodbye.mp3</URL>
< singer >the beatles</singer >
< lyrics >you Say yes, I say no</lyrics >
</Song >
< songs >
< song name >yesterday</>
<URL>http://www.mayia.com/beatlescom/beatles/mp3/mp3/yesterday.mp3</URL>
< singer >the beatles</singer >
< lyrics >yesterday, all I troubles seemed so far away</lyrics >
</Song >
</Online Play >
</xml>

<script language= "VBScript" >
Set Xml=xmlfile.recordset
Xml. MoveFirst
document.write "first record <BR>"
document.write XML ("song name") & "<BR>"
document.write XML ("singer") & "<BR>"
document.write XML ("URL") & "<BR>"
document.write XML ("lyrics") & "<BR><br>"
Xml. MoveNext
document.write "second record <BR>"
document.write XML ("song name") & "<BR>"
document.write XML ("singer") & "<BR>"
document.write XML ("URL") & "<BR>"
document.write XML ("lyrics") & "<BR>"
</script>
</body>
Click on the link below to view the example: view
In this HTML file, we added a pair of <xml></xml> tags to embed an internal XML document.
An XML document embedded in an HTML file follows the same rules as a standalone XML document, but eliminates the independence
The Declarations section of the XML document "<?xml version=" 1.0 "encoding=" gb2312 "?>". In the <XML> label,
We set the XML id:xmlfile so that the scripting language later accesses the XML object.

The "Set Xml=xmlfile.recordset" statement creates a cursor that can access XML. This cursor
Similar to the Recordset object in ASP, the method is almost exactly the same as the latter. Such as:

When we create a data cursor named XML with Set Xml=xmlfile.recordset, we can make the
Use the following methods and properties:

Xml. MoveFirst () move to first record
Xml. MoveNext () move to the next
Xml. MovePrevious () move to the previous bar
Xml. MoveLast () move to the last bar

Xml. BOF indicates that the cursor precedes the first record
Xml. EOF represents the cursor after the last record
Xml. Total number of RecordCount recordsets
Xml. AbsolutePosition Cursor Current position

Xml. AddNew () Add a record
Xml. Delete () Deletes a record

For example: We want to show the name of a song, we just have to move the cursor to the record, and then use the XML ("song name")
You can get the text between the < song name > and the </name > in the XML document. Very convenient.

Well, after understanding these things about XML, we can all start our real server offload
Move It!

Our thinking is:

1. The client issues a query condition to an ASP program on the server.
2. The ASP program responds and connects to the database.
3. The database returns the query results to the ASP program.
4. After obtaining the data, using the ASP program to format the data into XML format,
The query results are then built into the ASP's embedded XML object.
5. Page-by-Client implementation of XML (pagination method is similar to database paging)
6. Thereafter, no matter how many pages the client will turn the query results, no interaction with the server will occur.
In addition, even if the client disconnects the network cable, you can still browse the paging page that has not been browsed.

Here is a song I wrote the online Playback Program page program, consisting of two files:
Songlist.mdb a database, loaded with song information.
songlist.asp ASP program, the data in the database format into XML, the page is fully displayed, no matter how many times
"Next" and will not interact with the server.

Songlist.asp
Click on the link below to view the instance view

<title> Yinliang Online Play </title>
<style type= "Text/css" >
<!--
. Input
{
Background-color: #000000;
border: #000000;
Color: #FF9900;
}
-->
</style>

<body bgcolor= "#000000" text= "#FF9900" >
<% ', ' ', ', ', ', ', ' ', ' ', ' ', ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' '
Set Songcon = Server.CreateObject ("Adodb.connection")
Conpath = Server.MapPath ("Songlist.mdb")
Constr = "Driver={microsoft Access DRIVER (*.mdb)}; Dbq= "
Songcon.open (Constr & Conpath)
Set rs = Server.CreateObject ("ADODB.") Recordset ")
Rs.Open "SELECT * from Songlist", songcon,3,3
%>

<!--dynamically generate embedded XML documents, "online playback" is the root tag-->
<xml id = "XmlFile" >
< online play >
<%
If not rs.eof Then
While not rs.eof
%>
< songs >
< song ><%= trim (rs ("Song_name"))%></song name >
<url><%= Trim (rs ("Song_url"))%></url>
< performer ><%= Trim (rs ("Songer"))%></singer >
< lyrics ><%= Trim (rs ("Song_lyrics"))%></lyrics >
</Song >
<%
Rs.movenext
Wend
End If
%>
</Online Play >
</xml>
<div id= "Layer1" style= "Position:absolute; width:500px; height:59px; Z-index:1; left:118px; top:4px; " >
<!--Window Media Player Control-->
<object classid= "Clsid:22d6f312-b0f6-11d0-94ab-0080c74c7e95" width= "height=" "id=" Player "style=" width: 500px; Height:43px "viewastext>
<param name= "Audiostream" value= "-1" >
<param name= "AutoSize" value= "0" >
<param name= "AutoStart" value= "-1" >
<param name= "Animationatstart" value= "-1" >
<param name= "Allowscan" value= "-1" >
<param name= "Allowchangedisplaysize" value= "-1" >
<param name= "Autorewind" value= "0" >
<param name= "Balance" value= "0" >
<param name= "BaseURL" value= "" >
<param name= "Bufferingtime" value= "5" >
<param name= "Captioningid" value= "" >
<param name= "Clicktoplay" value= "-1" >
<param name= "CursorType" value= "0" >
<param name= "currentposition" value= "-1" >
<param name= "Currentmarker" value= "0" >
<param name= "Defaultframe" value= "" >
<param name= "Displaybackcolor" value= "0" >
<param name= "Displayforecolor" value= "16777215" >
<param name= "DisplayMode" value= "0" >
<param name= "Displaysize" value= "4" >
<param name= "Enabled" value= "-1" >
<param name= "Enablecontextmenu" value= "-1" >
<param name= "Enablepositioncontrols" value= "-1" >
<param name= "Enablefullscreencontrols" value= "0" >
<param name= "Enabletracker" value= "-1" >
<param name= "Filename" value= "" >
<param name= "Invokeurls" value= "-1" >
<param name= "Language" value= "-1" >
<param name= "Mute" value= "0" >
<param name= "Playcount" value= "1" >
<param name= "PreviewMode" value= "0" >
<param name= "Rate" value= "1" >
<param name= "Samilang" value= "" >
<param name= "Samistyle" value= "" >
<param name= "Samifilename" value= "" >
<param name= "SelectionStart" value= "-1" >
<param name= "Selectionend" value= "-1" >
<param name= "sendopenstatechangeevents" value= "-1" >
<param name= "sendwarningevents" value= "-1" >
<param name= "senderrorevents" value= "-1" >
<param name= "sendkeyboardevents" value= "0" >
<param name= "sendmouseclickevents" value= "0" >
<param name= "sendmousemoveevents" value= "0" >
<param name= "sendplaystatechangeevents" value= "-1" >
<param name= "showcaptioning" value= "0" >
<param name= "Showcontrols" value= "-1" >
<param name= "Showaudiocontrols" value= "-1" >
<param name= "Showdisplay" value= "0" >
<param name= "Showgotobar" value= "0" >
<param name= "Showpositioncontrols" value= "-1" >
<param name= "ShowStatusBar" value= "0" >
<param name= "Showtracker" value= "-1" >
<param name= "Transparentatstart" value= "0" >
<param name= "videoborderwidth" value= "0" >
<param name= "Videobordercolor" value= "0" >
<param name= "Videoborder3d" value= "0" >
<param name= "Volume" value= "0" >
<param name= "Windowlessvideo" value= "0" >
</OBJECT>
</div>


<div id= "Layer3" style= "Position:absolute; width:200px; height:115px; Z-index:3; left:120px; top:140px; " ></div>
<div id= "Layer4" style= "Position:absolute; width:191px; height:54px; Z-index:4; left:430px; top:199px; " >
<table width= "190" height= "border=" "1" align= "right" bordercolor= "#000000" bgcolor= "#FF9900" >
<tr>
&LT;TD height= "valign=" "Bottom" >
<div align= "center" ></div>

<div align= "Right" >
<input name= "Btnpre" type= "button" disabled= "true" id= "Btnpre" value= "Previous" >
</div></td>
</tr>
<tr>
&LT;TD valign= "Top" >
<div align= "Right" >
<input name= "btnnext" type= "button" id= "Btnnext" value= "Next Song" >
</div></td>
</tr>
</table>
</div>
<div id= "Layer2" style= "Position:absolute; width:503px; height:58px; Z-index:2; left:120px; top:67px; " >
<table width= "501" border= "1" >
<tr>
&LT;TD width= ><font color= "#FFFFFF" size= "2" > Play built-in songs:</font></td>
&LT;TD width= "317" >
<select name= "List" size= "1" id= "list" style= "WIDTH:328PX; Background-color:darkorange ">
<!--use loops to initialize the Drop-down list-->
<script language= "VBScript" >
Set Xml=xmlfile.recordset
Xml. MoveFirst
Dim num
for num=0 to XML. RecordCount-1
document.write ("<option value=" &xml ("url") & ">" &xml ("Song name") & "</OPTION>")
Xml. MoveNext
Next
Xml. MoveFirst
</script>
</SELECT>
</td>
&LT;TD width= "><div" align= "right" >
<input name= "Btnlan" type= "button" id= "Btnlan" value= "Play" >
</div></td>
</tr>
<tr>
<td><font color= "#FFFFFF" size= "2" > Play Network songs:</font></td>
<td><input name= "Texturl" type= text "id=" Texturl "style=" WIDTH:328PX; Background-color:darkorange;color: #000000; " ></td>
<td><div align= "Right" >
<input name= "btnnet" type= "reset" id= "Btnnet" value= "Play" >
</div></td>
</tr>
</table>
</div>
<div id= "Layer5" style= "Position:absolute; width:500px; height:20px; Z-index:5; left:120px; top:320px; " >
<p><font color= "#FFFFFF" size= "2" > is playing:
<input name= "Textsonger" type= "text" class= "input" id= "Textsonger" size= ">"
Sang the
<input name= "Textsongname" type= "text" class= "input" id= "Textsongname" size= ">"
</font></p>
</div>
<div id= "Layer6" style= "Position:absolute; width:500px; height:150px;
Z-index:6; left:120px; top:349px; " >
<textarea name= "area" cols= "," rows= "" "Id=" area "
Style= "Border-right:white double; Border-top:white Double;
Border-left:white Double; COLOR: #000000; direction:ltr;
Border-bottom:white Double; Background-color:darkorange;
Text-align:left ">
</textarea>
</div>

<!--Click events for each button-->
<script language= "VBScript" >
Sub Play ()
Textsonger.value=xml ("singer")
Textsongname.value=xml ("Song name")
Texturl.value= ""
Area.value=xml ("lyrics")
Player.filename=xml ("URL")

If XML. Absoluteposition=xml.recordcount Then
Btnnext.disabled=true
Else
Btnnext.disabled=false
End If

If XML. Absoluteposition=1 Then
Btnpre.disabled=true
Else
Btnpre.disabled=false
End If
End Sub

Sub Btnlan_onclick
Xml. MoveFirst
While XML ("URL") <>list.value
Xml. MoveNext
Wend
Call Play ()
End Sub

Sub Btnnet_onclick
Player.filename = Texturl.value
Textsonger.value = ""
Textsongname.value = ""
Area.value = "Custom Network song"
End Sub

Sub Btnpre_onclick
Xml. MovePrevious
List.selectedindex = list.selectedindex-1
Call Play ()
End Sub

Sub Btnnext_onclick
Xml. MoveNext
List.selectedindex = List.selectedindex + 1
Call Play ()
End Sub
</script>
</body>
Now, do you know how to lighten the server? ^-^

This article aims to explore, if there are errors and omissions, welcome correction and discussion.
Thank webmaster Miles these days to tireless help, no return, only to fill in this 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.