Create a message with ASP + XML

xiaoxiao2021-03-06  59

First, the reader guides the reader to help you master the text 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 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-use database storage data. Third, the advantage of the XML message may be asking you to ask the ASP TXT text can also achieve the function of not having the database, it is really possible, and there are many such a message on the Internet, but here I want to talk about ASP XML. Superiority. 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 the establishment of a message. Id. Id. - Defined as 1, Username We - Defined as 2, from there - defined as 3, Message Time - Righteous 4, User Homepage - Yi Yi 5, User's Mailbox - Defined as 6, Message Contents - Of course, the above is not necessary The reader can name itself and add to the relevant label, and combine them to get the list of list.xml 1 Huanzi Guangzhou 01-4-23 18:26:56 http: //page2000.xiloo. Com Lucaihui@cmmail.com This is my first XML file Note: must be added ENCODING = "GB2312" Otherwise, an 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) of XML data (index.asp) The function to be implemented is to read and display XML data. First create an XML object and read XML into 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 cLDNODES.ITEM (6) .Text 'won the message content yesterday' **************************************************** ******************************************* Take XML DOM to read data, obviously ObjrootSite's node corresponding to <newlist> 'Objr The node corresponding to OOTSITE.CHILDES.ITEM (Starnodes) is the <list> node because Item () is used in the <List> node, so Item () is used to identify the current node data, with the decrement of Starnodes's decrement <List> node rooted Move one by one read <List> node data.</p> <p>'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) '********************************************************** *********************************************** TEXT = Replace (Text, Chr (13), " <br> ") 'Alternative Enter TEXT = Replace (Text, Chr (32)," ")' Alternative 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="<%=HomePager = "Target = _BLANK TITLE =" Home "> Home </A> | | <A href="mailto: =email% "Title =" to <% = username%> 写 写> Mailbox </a> | | <font color = "# cc6633"> Message time: <% = posttime%> </ font> | <hr> <% = Text%> </ td> </ tr> <tr bgcolor = "# fffff" align = "right"> <td colspan = "2"> </ td> </ tr> <% starnodes = starnodes-1wend set Objxml = Nothing%> <tr bgcolor = "# ffffff" align = "right"> <td colspan = "2"> total <<% = PAGENUM% >> Page <% IF cint (Pageno) <> Pagenum Then 'page Response.write "<</p> <p>A href = 'index.asp? Pageno = "& (PAGENO 1) &"' "Previous </a>" End (Pageno) <> 1 ThenResponse.write "<a href = 'index.asp ? Pageno = "& (PAGENO-1) &" '> Next </a> "end if%> </ td> </ tr> </ table> </ body> </ html> six, establishment The new message program (postnew.asp) The function to be implemented is to write a new XML node, first create an XML object and read XML into the 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" get the path to the XML file Based on your virtual directory, different set objXml = server.createObject ("Microsoft.xmLDom") 'Create XML Objxml.Load (strsourceFile)' reading XML file into memory set objrootlist = objxml.documentelement.selectsinglenode ( "Newlist") 'Select <newlist.haschildnodes the' to judge <newlist> whether there is a child node (because if it is <newlist> is no child node, 'If it does not judge it in the first time At the time, Id = objrootlist.lastchild.FirstChild.text 1 'This is obtained here to insert the ID number of the child node, the first child node (firstchild) of <newList> (firstchild) The ID number plus 1 (here we are incremented 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 &" <usrname> "& bromwhere" <fromwhere> "& bromwhere &" </ fromwhere> "& Brstr & _ <posttime>" & posttime & "< / PostTime> "& Brstr & _ <homepage>" &</p> <p>HomePage & "</ HomePage>" & Brstr & _ "<email>" & brrs & _ "<text>" & text & "</ text>" & brrs "</ list>" & chr (13) 'Establish XML fragment based on the obtained data set objxml2 = server.createObject ("Microsoft.xmLDom")' Creating a new XML ObjXML2.LoadXML (XMLNode) 'reads XML version to SET ROOTNEWNODE = Objxml2.documentelement' Get the root node of Objxml2 Objrootlist.Appendchild (rootnewnode) 'Plug the XML fragment into the Objxml.Save (strsourcefile)' stores lsit.xml file (because not stored by List.xml 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 color =" 2 "> <font color =" # fff "> new message </ font> </ td> </ tr> < Tr bgcolor = "# Efefef"> <td width = 19% "align ="</p> <p>Right "> Name: </ td> <TD width =" 81% "> <input type =" text "name =" username "> ** </ td> </ tr> <tr> =" # efefef "> <Td width = "19%" align = "right"> from: </ td> <td width = "81%"> <input type = "text" name = "fromwhere" value = "China"> </ td > </ Tr> <tr bgcolor = "# Efefef"> <td width = "19%" align = "right"> Home: </ td> <td width = "81%> <input type =" text " Name = "homepage" value = "http: //"> </ td> </ tr> <tr> <Td width = "19%" align = "right"> email: </ td > <Td width = "81%"> <input type = "text" name = "email"> </ td> </ tr> <tr bgcolor = "# Efefef"> <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 =</p></div><div class="text-center mt-3 text-grey"> 转载请注明原文地址:https://www.9cbs.com/read-112056.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="112056" 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.042</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 = 'ebKseB1uVH5_2BVMUSwVfS070g_2FVjzjFfT8BDiRPBh70uCsjnjiNhVB2r_2FFzulnejNDa1ONTXdtp_2BFPDYOyzkK2Q_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>