Asp+|xml use Asp+xml to create a message book
Source: www.yesky.com
First, the reader guide
The Reader guide helps you master the outline of this article. Lest you read most of it to understand this article is not suitable for you, causing you visual pollution.
If you're writing a program with Asp+xml, or you're learning XML, it's worth seeing.
Read the knowledge required in this article, have a basic understanding of the ASP, have a basic understanding of XML and DOM, if you do not understand then you can basically hold the Asp+xml and DOM applications by studying this article, and can write out the Asp+xml programs that are more advanced according to Ben Wen van.
Ii. Basic Ideas
The idea of this paper is to use ASP and DOM to read and store XML data, and to store message information with XML data to achieve the function of storing data in the same database.
Third, the advantages of the XML message book
Perhaps you will be asked to use Asp+txt text can also be achieved without the database of the function of the message, good indeed can do, and there are many online such a message this free download, but here I want to talk about the advantages of asp+xml.
1, xml+asp faster than asp+txt speed. You may also find that when the TXT file is very rare when the speed is surprisingly fast, but as the message information increased TXT text, speed is surprisingly slow this is the weakness of asp+txt. Of course I can't say asp+xml must have been surprisingly fast, but it's a lot quicker than asp+txt, of course, with the increase in message information the XML text increases quickly, but it's a lot better than txt (this can be tested from the was test that readers can test themselves), Of course, asp+xml than the database, because the database for the query to do a special optimization, and XML is only plain text, in the ASP to create the image is to read all the XML data into memory, if the amount of data can imagine the speed will slow down. Then you might ask me, when do I use relational databases to store data, and when do I store data in XML? I'm also going to mention here that when the data is more complex and random, it's more appropriate to use XML data, and that's when you plan to read and use the data on different operating systems. Do not use XML files to store data if you are not in a critical moment or do not support the database's space.
2, easy to read the XML data, txt text is more difficult to operate, we must read a row of judgment, but also very multi-functional can not be, can only prepare a relatively simple message, and the XML data is different, using DOM can easily access each node, Instead of txt those annoying readline () witeline (), we can randomly add delete update a certain we are interested in the node, the use of ASP or JS or data island can easily do this, of course I am here to consider compatibility, with ASP to read XML data, Instead of using the data island to read the node data (since only IE5 versions support data island Technology) and ASP to actually do not exist these questions because the customer is getting HTML files.
3, the XML data Kua operating system, as long as we store this data as XML so that the data can be He Ki it language or system recognized, without doing what should be changed. TXT obviously does not have these performance. For example, our message on the Internet can be directly converted into a WAP format on the phone to display.
IV. create an XML file to store message information (list.xml)
We do not intend to use DTDs here, because we are the XML data that we have compiled and tested, so we do not need a DTD to validate (if you are interested in this you can certainly add one that does not affect the program's operation). Now let's take a look at the basics of creating a message book.
0, Message ID number--defined as <id>
1, user name US--defined as <username>
2, from there--defined as <fromwhere>
3, message time set-the meaning of the <Posttime>
4, User homepage set-righteousness is
5, the user's mailbox--defined as <email>
6, message content set-the meaning of the <text>
Of course, the above is not necessary to the reader can name and add and subtract related tags, put them together to get the List.xml file
<?xml version= "1.0" encoding= "gb2312"?
<site>
<NewList>
<list>
<id> 1 </id>
<username> Harsh child </username>
<fromwhere> Guangzhou, China </fromwhere>
<Posttime> 01-4-23 18:26:56 </Posttime>
<email> lucaihui@cmmail.com </email>
<text> This is my first XML file </text>
</list>
</NewList>
</site>
Note: You must add encoding= "gb2312" otherwise the error will be invalid because the XML does not support Chinese by default. The <site> is the root node <NewList> <ist>, and so on, as child nodes. I don't have much to say about the document, so we should see it. The next step is how we can show it.
V. Create ASP files to display XML data (index.asp)
The function of this file is to read and display the XML data, first create an XML image and then read the XML into memory, and use the DOM to isolate the data we want.
<%
strSourceFile = Server.MapPath ("/") & "\list.xml"
' Get the path to the XML file, which is different depending on your virtual directory.
Set objxml = Server.CreateObject ("Microsoft.FreeThreadedXMLDOM")
' Create an XML pair as a free thread
Objxml.load (strsourcefile) ' reads the XML file into memory
Set objrootsite = ObjXML.documentElement.selectSingleNode ("NewList")
' Select the NewList node
%>
<title> Message Book </title>
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 ">
<style type= "Text/css"
!--
TD {Font-family: "Song body"; font-size:9pt; Text-decoration:none}
A {font-family: "Song body"; Font-size:9pt color: #0066CC; Text-decoration:none}
a:hover {color: #FF6600; Text-decoration:underline}
-->
</style>
<table width= "80%" border= "0" cellspacing= "1" cellpadding= "4" align= "center" bgcolor= "#CCCCCC"
<TR bgcolor= "#000000" >
<TD colspan= "2" ><font color= "#FFFFFF" "Yi Pu <a Href=" postnew.asp "><font color= #FFFFFF > write new message </font> </a> </font> </td>
</tr>
<%
PageSize = 10 ' Suppose each page shows 10 messages
Allnodesnum =objrootsite.childnodes.length-1
' Get the child node data (since the maximum number of child nodes from the number of nodes is 0 minus 1)
Pagenum=allnodesnum\pagesize+1 ' Calculate the total number of pages
Pageno=request.querystring ("PageNo")
If pageno= "then" if it is every time you get the page, navigate to each page to display the latest message
Pageno=pagenum
End If
Starnodes=pageno*pagesize-1 ' Get Start node
Endnodes= (PageNo-1) *pagesize ' Get End node
If endnodes<0 Then
Endnodes=0
End If
If Starnodes>allnodesnum then ' determines whether the number of starting nodes exceeds the total number of nodes
endnodes=endnodes-(Starnodes-allnodesnum)
' If the difference between the end node minus (Starnodes-allnodesnum) is exceeded, the next rcas is out of bounds error
Starnodes=allnodesnum
End If
If endnodes<0 Then
Endnodes=0
End If
While Starnodes>=endnodes
' Read node data from end node to super start node
Username = ObjRootsite.childNodes.item (starnodes). Childnodes.item (1). Text
' Get user name
Fromwhere = ObjRootsite.childNodes.item (starnodes). Childnodes.item (2). Text
' Get users from there
Posttime = objRootsite.childNodes.it