Create a message with ASP + XML

zhaozj2021-02-17  58

Create a message with ASP XML

Source: www.yesky.com

First, the reader guidelines

The reader guidelines help you master the syndrome of this article. Solve you to see that this article is not suitable for you, give you visual pollution.

If you are writing some programs with ASP XML, or you are learning XML, it is worth seeing.

Read the knowledge required by this article, there is a basic understanding of the ASP, which is basically understanding the XML and DOM. If you don't know, then you can basically grasp the application of ASP XML and DOM through this article, and can write from this article More advanced ASP XML programs.

Second, the basic idea

This article is based on the use of ASP and DOM to read and store XML data, and utilize XML data to store message information, and achieve the functionality of the same withdrawal database stored data.

Third, the advantage of XML message

Maybe you will ask the ASP TXT text to achieve the function that doesn't have a database, it is really possible, and there is a lot of such a message on the Internet, but here I want to tell the superiority of ASP XML.

1, XML ASP is fast than ASP TXT speed. Maybe you also found that when the txt file is very fast, the speed of the message information is large, but the speed is surprisingly slow. This is the weakness of the ASP TXT. Of course, I can't say that ASP XML must be surprising, but it is much better than ASP TXT, of course, as the message information increases the increase of XML text, it is very fast, but it is still better than TXT. Many (this point can be proved from the WAS test), of course, the ASP XML is not a database, because the database is specially optimized, and XML is just plain text, and the ASP is established to read all the XML data. In the memory, if the amount of data is large, it is conceivable that the speed will slow down. Then you will ask if I use the relationship data stock data, when is it to store data with XML? I will mention it here, that is, when the data is more complicated, I use XML data, and it is what you intend to read it in different operating systems. That is XML. If you are a normal data, don't you store data with an XML file when you don't support the database space or if you don't support the database. 2, XML data is easy to readily readily, txt text is more difficult to operate, we must read judgment in one line, and many features can not be real, can only prepare a relatively simple message, and XML data is different. With DOM, you can easily access each node, not TXT's annoying readline () witeline (), we can add to delete a node we are interested in, using ASP or JS or data islands to easily At this point, of course, I will use the ASP to read the XML data for the time of considering compatibility, and use the data island to read node data (because only IE5 or higher is supported by the data island technology) and use ASP. There is no such question because the customer gets the HTML file.

3, XML data boast system nature, as long as we store these data as XML then these data can be identified by the language or system, without doing what changes. TXT obviously does not have these properties. For example, our message information on the Internet can be converted directly into the WAP format display on the phone. Fourth, establish the XML file (list.xml) of the store message information (List.xml) We don't plan to use DTD, because we are our own XML data, so you don't need DTD to verify (if you are interested in this, of course you can Add one this does not affect the operation of the program). Now let's take a look at the basic elements of establishing a message.

0, message ID number - defined as

1. Username We - Defined as

2, from there - defined as

3, message time - 为

4. User Homepage - 为

5, user's mailbox - defined as

6, message content - 为

Of course, the above is not a must-have to name and add relevant labels, and combine them to get the list of list.xml.

1 Huanzi China Guangzhou < Posttime> 01-4-23 18:26:56 http://page2000.xiloo.com lucaihui@cmmail.com This is me The first XML file

Note: You must add eNCoding = "GB2312" otherwise error is an illegal character, because XML does not support Chinese by default. is the root node or the like for a child node. I don't have much to understand that everyone should also understand. The next is how we will show it.

V. Establish an ASP file (INDEX.ASP) that display XML data

The functionality to be implemented is to read and display XML data, first create an XML object and read XML into the memory, and use DOM to separate the data we want.

<% Strsourcefile = server.mappath ("/") & "/list.xml" Gets the path to the XML file here, according to your virtual directory, different set objXml = server.createObject ("Microsoft.FreethreadedEdxmldom) 'is free Thread Create an XML ObjXML.Load (strsourceFile) 'Read XML file into memory set objrootsite = objxml.documentelement.selectsinglenode ("newlist")' Select NewList node%> message book / title> <meta http-equiv = "content-type" content = "text / html; charset = gb2312"> <style type = "text / css"> <! - td {font-family: "Song"; FONT-SIZE: 9pt; Text-Decoration: none} a {font-family: "Song"; 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> <td color =" 2 "> <font color =" # ffffff "> message 溥 <a href =" PostNew. ASP> <font color = # fff> Write a new message </ font> </a> </ font> </ td> </ tr> <% pagesize = 10 'assumes 10 messages allNodesnum = ObjRootsite. ChildNodes.Length-1 'gets child node data (because the maximum number of child nodes starting from the number of nodes) PAGENUM = AllNod ESNUM / PAGESIZE 1 'Calculate the total number of pages Pageno = Request.QueryString ("Pageno") if Pageno = "" ""</p> <p>If you get a page, you can locate each page to display the latest message Pageno = PageNuMend ifstarnodes = Pageno * Pagesize-1 'Get the start node endnodes = (Pageno-1) * Pagesize' get the end node if endnodes <0 thenendnodes = 0END IFIF Starnodes> Allnodesnum kilnod The number of start nodes exceeds the total number of nodes Endnodes = endnodes- (Starnodes-AllNodesnum) 'If the end node is subtracted to subtract (Starnodes-AllNodesnum) does otherwise subscript superior error StarNodes = AllNodesNumend ifif EndNodes <0 thenEndNodes = 0end ifwhile StarNodes> = EndNodes 'read from the end node to the start node over between data username = objRootsite.childNodes.item (StarNodes) .childNodes.item (1) .text' Get the username fromwhere = objroots.childNodes.item (starnodes) .childNodes.Item (2) .Text 'get users from there postetime = objroots.childNodes.item (starnodes) .childnodes.Item (3) .Text' Get message time homepage = objRootsite.childNodes.item (StarNodes) .childNodes.item (4) .text 'to obtain user's home email = objRootsite.childNodes.item (StarNodes) .childNodes.item (5) .text' to obtain user Eamiltext = objRootsite.childNodes .item (starnodes) .childnodes.Item (6) .Text 'won the content yesterday</p> <p>'********************************************************** *************************** 'Here, the XML DOM is read, clearly the Node corresponding to the object of ObjrootSite. <Newlist> 'ObjRootsite.childNodes.item (Starnodes) The node is the <list> node because it is not allowed to use Item () to identify the current node data, with the decrement of StarNodes <List> node Follow up to the upright one by one read <List> node data. 'objRootsite.childNodes.item (Starnodes) .childnodes.Item (1) .Text The node corresponding to the specific text value of each node, here (1), the username username (because <list> node) The child node is what we really want) '********************************************************** ***********************************************</p> <p>TEXT = Replace (Text, Chr (13), "<br>") 'replaces the carriage return text = Replace (Text, Chr (32), "")' replacement space%> <tr bgcolor = "# f0f0f0> < Td width = "21%" Height = "94" Valign = "TOP"> Name: <% = Username%> <br> From: <% = fromwhere%> <br> </ td> <td width = "79 % "Height =" 94 "Valign =" TOP "> | <a href="<% =" TARGET = _BLANK TITLE = "Home"> Home </A> | | < a href = "mailto: <% = email%>" Title = "give <% = username%>" letter box </a> | | <font color = "# cc6633> Message time: <% = posttime %> </ Font> | <hr> <% = text%> </ td> </ tr> <tr ("# fffff" Align = "Right"> <TD colSpan = "2"> </ td> </ Tr> <% starnodes = starnodes-1Wend set objxml = not%> <tr bgcolor = "# fff" align = "right"> <td colspan = "2"> a total of <<% = PAGENUM% >> Page < % IF CINT (PAGENO) <> Pagenum Ten 'Page Response.Write "<a href='index.asp?pageno="undex.asp?pageno="" Previous Page </A> "End IFIF CINT Pageno) <> 1 ThenResponse.write "<a href = 'index.asp? Pageno =" & (PAGENO-1) & "'</p> <p>> Next </a> "end if%> </ td> </ tr> </ table> </ body> </ html> 6, establish a new message (Postnew.asp)</p> <p>The functionality to be implemented is to write a new XML node, first create an XML object and read XML into memory, using the appendchild () method to join our generated XML node.</p> <p><% Username = Request.form ("Username") if Username <> "" "" fromwhere = Request.form ("fromwhere") HomePage = Request.form ("HomePage") Email = Request.form ("email" text = Request.form ("text") text = replace (text, "<", "<") posttime = now () strsourcefile = server.mappath ("/") & "/list.xml"</p> <p>'Get the path to the XML file here, depending on your virtual directory, different set objxml = server.createObject ("Microsoft.xmLDom")' Create an XML Objxml.Load (strsourcefile) 'reading the XML file into the memory set objrootlist = Objxml.documentelement.selectsinglenode ("newlist") 'Select <newlist> Node if objrootlist.haschildnodes dam h <newlist> Is there a child node (because if it is <newlist> is no child node,' If not judge When you first operate, you will report an error ID = ObjrootList.lastchild.FirstChild.text 1 'This will get the ID number that will be inserted into the child node, the ID number is <NewList> of the last child node (Lastchild) The ID number of the firstchild is 1 (here we increment in accordance with the ID number of the relational database) Else ', if there is no word sub-node, the first message ID number is set to 1ID = 1END ifbrstr = CHR (13) & chr (10) & chr (9) 'In order to insert a node wrap space in the XML file, neat' (of course, you can use it just to look like this) XMLNode = Brstr & "<List>" & Brstr & _ "<ID > "& ID &" </ ID> "& Brstr & _" <username> "& username &" </ username> "& bromwhere" <fromwhere> "& fromwhere &" </ fromwhere> "& Brstr & _" <PostTime> "& PostTime &" < / PostTime> "& Brstr & _" <HomePage> "& Brstr & _" <email> "& email &" </ email> "& brstr & _" <text> "& Text &" </ text> & Brstr & _ "</ List>" & chr (13) 'Established XML fragment set objXml2 = server.createObject ("Microsoft.xmLDom") based on the data obtained</p> <p>XML to create a new image objXML2.loadXML (XMLnode) 'version of the XML fragment into memory set rootNewNode = objXML2.documentElement' of the root node obtained objXML2 objRootlist.appendChild (rootNewNode) 'fragment was inserted into the XML List.xml in objXML .save (strsourcefile) 'Stores lsit.xml files (because not locked list.xml is updated only in memory) Set objxml = nothingset Objxml2 = NothingResponse.write "Thank you message" response.Endend IF%> <html> < Head> <title> Untitled Document </ title> <meta http-equiv = "content-type" content = "text / html; charSet = GB2312"> <style type = "text / css"> <! - td { FONT-SIZE: 9pt} -> </ style> </ head> <body bgcolor = "# 0099cc" text = "# 000000"> <table width = "80%" border = "0" cellspacing = "1" Cellpadding = "4" align = "center" bgcolor = "# fff"> <form action = "postnew.asp" method = "post" name = "form1"> <tr bgcolor = "# 000000> <TD colspan = "2"> <font color = "# ffffff"> New message </ font> </ td> </ tr> <tr bgcolor = "# Efefef"> <td width = "19%" align = "Right"> Name: </ TD> <TD Width = "81%"> <input type = "text" name = "username"> ** </ td> </ tr> <tr bgcolor = "# Efefef"> <TD Width = "19%" align = "right"> From: </ td></p> <p><TD width = "81%"> <input type = "text" name = "fromwhere" value = "China"> </ td> </ TD> <tr bgcolor = "# Efefef"> <td width = 19 % "Align =" Right "> Home: </ td> <td width =" 81% "> <input type =" text "name =" homepage "value =" http: /// "> </ td> </ Tr> <TR BGCOLOR = "# Efefef"> <TD width = "19%" align = "right"> email: </ td> <td width = "81%> <input type =" name = " Email "> </ td> </ tr> <trs> <TD width =" 19% "align =" right "valign =" top "> content: </ td> <td width =" 81%> <textarea name = "text" cols = "60" rows = "10"> </ teXTAREA> </ td> </ tr> <tr bgcolor = "# Efefef"> <td width = "19% "Align =" right "> </ td> <TD width =" 81%> <input type = "submit" name = "submit" value = "submit"> <input type = "reset" name = "submit2" Value = "Refill"> </ TD> </ TR> </ form> </ table> </ body> </ html> seven, summary</p></div><div class="text-center mt-3 text-grey"> 转载请注明原文地址:https://www.9cbs.com/read-29904.html</div><div class="plugin d-flex justify-content-center mt-3"></div><hr><div class="row"><div class="col-lg-12 text-muted mt-2"><i class="icon-tags mr-2"></i><span class="badge border border-secondary mr-2"><h2 class="h6 mb-0 small"><a class="text-secondary" href="tag-2.html">9cbs</a></h2></span></div></div></div></div><div class="card card-postlist border-white shadow"><div class="card-body"><div class="card-title"><div class="d-flex justify-content-between"><div><b>New Post</b>(<span class="posts">0</span>) </div><div></div></div></div><ul class="postlist list-unstyled"> </ul></div></div><div class="d-none threadlist"><input type="checkbox" name="modtid" value="29904" checked /></div></div></div></div></div><footer class="text-muted small bg-dark py-4 mt-3" id="footer"><div class="container"><div class="row"><div class="col">CopyRight © 2020 All Rights Reserved </div><div class="col text-right">Processed: <b>0.043</b>, SQL: <b>9</b></div></div></div></footer><script src="./lang/en-us/lang.js?2.2.0"></script><script src="view/js/jquery.min.js?2.2.0"></script><script src="view/js/popper.min.js?2.2.0"></script><script src="view/js/bootstrap.min.js?2.2.0"></script><script src="view/js/xiuno.js?2.2.0"></script><script src="view/js/bootstrap-plugin.js?2.2.0"></script><script src="view/js/async.min.js?2.2.0"></script><script src="view/js/form.js?2.2.0"></script><script> var debug = DEBUG = 0; var url_rewrite_on = 1; var url_path = './'; var forumarr = {"1":"Tech"}; var fid = 1; var uid = 0; var gid = 0; xn.options.water_image_url = 'view/img/water-small.png'; </script><script src="view/js/wellcms.js?2.2.0"></script><a class="scroll-to-top rounded" href="javascript:void(0);"><i class="icon-angle-up"></i></a><a class="scroll-to-bottom rounded" href="javascript:void(0);" style="display: inline;"><i class="icon-angle-down"></i></a></body></html><script> var forum_url = 'list-1.html'; var safe_token = 'z4kRhwF8Lc2TUtIXKd_2F2FYTEQQ_2FLhg3wJ_2Bwb93vInQiEbxL4ch1ptGOB3Ui5xeJYeqzt3xMQjbUF2MMEea_2BFQw_3D_3D'; var body = $('body'); body.on('submit', '#form', function() { var jthis = $(this); var jsubmit = jthis.find('#submit'); jthis.reset(); jsubmit.button('loading'); var postdata = jthis.serializeObject(); $.xpost(jthis.attr('action'), postdata, function(code, message) { if(code == 0) { location.reload(); } else { $.alert(message); jsubmit.button('reset'); } }); return false; }); function resize_image() { var jmessagelist = $('div.message'); var first_width = jmessagelist.width(); jmessagelist.each(function() { var jdiv = $(this); var maxwidth = jdiv.attr('isfirst') ? first_width : jdiv.width(); var jmessage_width = Math.min(jdiv.width(), maxwidth); jdiv.find('img, embed, iframe, video').each(function() { var jimg = $(this); var img_width = this.org_width; var img_height = this.org_height; if(!img_width) { var img_width = jimg.attr('width'); var img_height = jimg.attr('height'); this.org_width = img_width; this.org_height = img_height; } if(img_width > jmessage_width) { if(this.tagName == 'IMG') { jimg.width(jmessage_width); jimg.css('height', 'auto'); jimg.css('cursor', 'pointer'); jimg.on('click', function() { }); } else { jimg.width(jmessage_width); var height = (img_height / img_width) * jimg.width(); jimg.height(height); } } }); }); } function resize_table() { $('div.message').each(function() { var jdiv = $(this); jdiv.find('table').addClass('table').wrap('<div class="table-responsive"></div>'); }); } $(function() { resize_image(); resize_table(); $(window).on('resize', resize_image); }); var jmessage = $('#message'); jmessage.on('focus', function() {if(jmessage.t) { clearTimeout(jmessage.t); jmessage.t = null; } jmessage.css('height', '6rem'); }); jmessage.on('blur', function() {jmessage.t = setTimeout(function() { jmessage.css('height', '2.5rem');}, 1000); }); $('#nav li[data-active="fid-1"]').addClass('active'); </script>