Use ASPXML to create a message book

Source: Internet
Author: User
I. readers guide readers to help you grasp the synopsis of this article. So that you do not understand that this article is not suitable for you and may cause visual pollution to you. If you are writing some programs using ASP + XML, or you are learning XML, it is worth reading. Browse Book

I. Reader guide

Reader guide helps you grasp the synopsis of this article. So that you do not understand that this article is not suitable for you and may cause visual pollution to you.

If you are writing some programs using asp xml, or you are learning XML, it is worth reading.

Knowledge required to browse this article, basic understanding of ASP, basic understanding of XML and DOM, if you do not know, you can use ASP + XML and DOM on the basis of learning this article, and write more advanced ASP + XML programs based on this article.

II. basic ideas

The idea of this article is to use ASP and DOM to read and store XML data, and use XML data to store message information, so as to achieve the same function of storing data in databases.

III. Advantages of XML message Books

You may ask whether using ASP + TXT text can also achieve the function of not having to use real-time messages in the database. it is good to do it, and there are also many such message books on the Internet that can be downloaded for free, but here I want to talk about the superiority of ASP + XML.

1. XML + ASP is faster than ASP + TXT. You may also find that when there are few TXT files, the speed is surprisingly fast. However, as the message information increases, the TXT text increases, and the speed is surprisingly slow, this is the weakness of ASP + TXT. Of course, I can't say that ASP + XML must be surprisingly fast, but it is much faster than ASP + TXT. of course, as the message information increases, the XML text increases rapidly, however, it is much better than TXT (this can be verified by the WAS test). of course, ASP + XML is not comparable to the database, because the database has made special optimization on the query, XML is only plain text. the establishment of an ASP object seems to require all the XML data to be read into the memory. if the data volume is large, it can be imagined that the speed will slow down. Then you may ask, when will I use relational databases to store data and XML to store data? By the way, it is appropriate to use XML data when the data is more complex than the random rate, there is also the time when you plan to read the application data on different control systems. If you are using common data, do not use XML files to store data when it is not critical or does not support database space.

2. XML data is easy to read. TXT text is relatively difficult to control. we must read and judge a row by row. In addition, many functions cannot be used in practice. we can only compile a relatively simple message book, XML data is different. DOM can be used to easily visit every node, instead of the annoying Readline () Witeline () in TXT, we can randomly delete and update a node that we are interested in. using ASP, JS, or data Island, we can easily implement this. of course, I will consider compatibility here, using ASP to read XML data, instead of using data Islands to read node data (only IE5 or later versions support data Islands) in practice, ASP does not exist because the customer obtains HTML files.

3. XML data is dominant in the system. as long as we store the data as XML, the data can be identified by the language or system, without any correction. TXT obviously does not have these performances. For example, our messages on the Internet can be directly converted to wap and displayed on the mobile phone.

4. create an XML file (List. xml) for storing message information)

We do not intend to apply DTD here, because we have compiled and tested the XML data, therefore, you do not need a DTD for verification (if you are interested in this, you can add a program that does not affect the running of the program ). Now let's take a look at the basic elements of creating a message book.

0. message id -- defined as <id>

1. username -- defined as <username>

2. from there -- defined as <fromwhere>

3. set the message time to <Posttime>

4. set the user homepage to
5. user mailbox-defined as <email>

6. set the message content to <text>

Of course, the above is not necessary for readers to name and add or subtract the corresponding tags, and combine them to get the List. xml file.

<? Xml version = "1.0" encoding = "gb2312"?>
<Site>
<NewList>
<List>
<Id> 1 </id>
<Username> Example </username>
<Fromwhere> Guangzhou, China </fromwhere>
<Posttime> 01-4-23 18:26:56 </Posttime>
<Homepage> http://page2000.xiloo.com <Email> lucaihui@cmmail.com </email>
<Text> This is my first XML file </text>
</List>
</NewList>
</Site>

5. create an ASP File (index. asp) that displays XML data)

The function of this file is to read and display XML data. First, create an XML object and then read the XML into the memory, and use the DOM to output the data we want.

Reference content is as follows:
<%
StrSourceFile = Server. MapPath ("/") & "\ List. xml"
'Obtain the path of the XML file. The path varies depending on your virtual directory.
Set objXML = Server. CreateObject ("Microsoft. FreeThreadedXMLDOM ")
'Create an XML object with a free thread
ObjXML. load (strSourceFile) 'reads the XML file into the memory.
Set objRootsite = objXML.doc umentElement. selectSingleNode ("NewList ")
'Select a NewList node.
%>
<Html>
<Head>
<Title> message book </title>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312">
<Style type = "text/css">
<! --
Td {font-family: ""; font-size: 9pt; text-decoration: none}
A {font-family: ""; font-size: 9pt; color: # 0066CC; text-decoration: none}
A: hover {color: # FF6600; text-decoration: underline}
-->
</Style>
</Head> <body bgcolor = "# 0099CC" text = "#000000">
<Table width = "80%" border = "0" cellspacing = "1" cellpadding = "4" align = "center" bgcolor = "# CCCCCC">
<Tr bgcolor = "#000000" type = "codeph" text = "/codeph">
<Td colspan = "2"> <font color = "# FFFFFF"> Comment <a href = "PostNew. asp "> <font color = # FFFFFF> write new messages </font> </a> </font> </td>
</Tr>
<%
PageSize = 10' suppose 10 messages are displayed on each page
AllNodesNum = objRootsite. childNodes. length-1
'Obtain the subnode data (because the maximum number of subnodes starting from 0 must be reduced by 1)
PageNum = AllNodesNum \ PageSize 1 'calculates the total number of pages
PageNo = request. querystring ("PageNo ")
If PageNo = "" then', if each page is obtained, the latest message is displayed on each page.
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', determine whether the number of start nodes exceeds the total number of nodes.
EndNodes = EndNodes-(StarNodes-AllNodesNum)

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.