ASP + xml = "create a simple message book, three ASP files, with an XML

Source: Internet
Author: User

Index. asp: display XML files and pages
<%
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. xmldom ")
'Create an XML object with a free thread
Objxml. Load (strsourcefile) 'reads XML files into memory
Set objrootsite = objxml.doc umentelement. selectsinglenode ("newlist ")
'Select A newlist node.
%>
<HTML>
<Head>
<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 a new message
</Font> </a> </font> </TD>
</Tr>
<%
Pagesize = 3' suppose 10 messages are displayed on each page
Allnodesnum = objrootsite. childnodes. Length-1
'Response. Write objrootsite. childnodes. Length
'Response. End
'Obtain the subnode data (because the maximum number of subnodes starting from 0 must be reduced by 1)
Pagenum = allnodesnum \ pagesize + 1 calculate 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
'Response. Write "starnodes and allnodesnum =" & starnodes & "----" & allnodesnum & "<br>"
If starnodes> allnodesnum then', determine whether the number of start nodes exceeds the total number of nodes.
Endnodes = endnodes-(starnodes-allnodesnum)
'If the value exceeds, the End Node minus the difference (starnodes-allnodesnum). Otherwise, the subscript will be out of bounds.
Starnodes = allnodesnum
End if
'Response. Write "starnodes = _________" & starnodes & "---" & "<br>"
If endnodes <0 then
Endnodes = 0
End if
While starnodes> = endnodes
'Read node data from the end node to the superstart Node
'Response. Write "id =" & objrootsite. childnodes. Item (starnodes). childnodes. Item (0). Text

Id = objrootsite. childnodes. Item (starnodes). childnodes. Item (0). Text
'Id No.
Username = objrootsite. childnodes. Item (starnodes). childnodes. Item (1). Text
'Get Username
Fromwhere = objrootsite. childnodes. Item (starnodes). childnodes. Item (2). Text
'Get the user from there
Posttime = objrootsite. childnodes. Item (starnodes). childnodes. Item (3). Text
'Get message time
Homepage = objrootsite. childnodes. Item (starnodes). childnodes. Item (4). Text
'Get user Homepage
Email = objrootsite. childnodes. Item (starnodes). childnodes. Item (5). Text
'Get user eamil
TEXT = objrootsite. childnodes. Item (starnodes). childnodes. Item (6). Text
'The received Response Message Content
'*************************************** **************************************
'Here we use the xml dom to read data. Obviously, the node corresponding to the object of the objrootsite is <newlist>
The node corresponding to 'objrootsite. childnodes. Item (starnodes) is the <list> node that uses item () because no <list> node exists ()
'To identify the data of the current node. with the decreasing of starnodes, the <list> node reads the data of <list> nodes one by one.
'Objrootsite. childnodes. Item (starnodes). childnodes. Item (1). the node corresponding to text is the text value of each node. Here
'(1) corresponds to the username (because the sub-nodes of the <list> node are what we really want)
'*************************************** ***************************************
TEXT = Replace (text, CHR (13), "<br> ")
'Replacement carriage return
TEXT = Replace (text, CHR (32 ),"")
'Replacement space
%>
<Tr bgcolor = "# f0f0f0">
<TD width = "21%" Height = "94" valign = "TOP"> ID: <% = ID %> <br> name: <% = username %> <br>
From: <% = fromwhere %> <br>
<A href = 'postedit. asp? Id = <% = ID %> '> edit message </a>
</TD>
<TD width = "79%" Height = "94" valign = "TOP"> | <a href = "<% = homepage %>" target = _ blank Title = "<% = username %> Home Page "> Home page </a>
| <A href = "mailto: <% = Email %> "Title =" write to <% = username %> "> mailbox </a> | <font color =" # cc6633 ">
Message time: <% = posttime %> </font> |
<HR>
<% = Text %> </TD>
</Tr>
<Tr bgcolor = "# ffffff" align = "right">
<TD colspan = "2"> </TD>
</Tr>
<%
Starnodes = StarNodes-1
Wend
Set objxml = nothing
%>
<Tr bgcolor = "# ffffff" align = "right">
<TD colspan = "2"> total pages <% = pagenum %>
<%
If CINT (pageno) <> pagenum then' page
Response. Write "<a href = index. asp? Pageno = "& (pageno + 1) &"> previous page </a>"
End if
If CINT (pageno) <> 1 then
Response. Write "<a href = index. asp? Pageno = "& (PageNo-1) &"> next page </a>"
End if
%>
</TD>
</Tr>
</Table>
</Body>
</Html>

========================================================== ==========================================================
Postnew. asp add message content

<%
Username = request. Form ("username ")
If username <> "" then
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"
'Obtain the path of the XML file. The path varies depending on your virtual directory.
Set objxml = server. Createobject ("Microsoft. xmldom ")
'Create an XML Object
Objxml. Load (strsourcefile)
'Read XML files into memory
Set objrootlist = objxml.doc umentelement. selectsinglenode ("newlist ")
'Select the <newlist> node
If objrootlist. haschildnodes then
'Determine whether <newlist> has subnodes (because if each <newlist> operation has no subnodes, an error is reported when the first operation is not performed.
Id = objrootlist. lastchild. firstchild. Text + 1
'Obtain the ID number of the child node to be inserted. the ID number is the first child node (firstchild) of the last child node (lastchild) of <newlist>)
'Id' plus 1 (Here we increase progressively according to the IDSN of the relational database)
Else
'If there is no word subnode, it is the first time the Message ID is set to 1
Id = 1
End if
Brstr = CHR (13) & CHR (10) & CHR (9)
'To insert nodes in the XML file with line breaks and spaces arranged neatly
'(Of course you don't need to use it to make XML data look good)
Xmlnode = brstr & "<list>" & brstr &_
"<ID>" & ID & "</ID>" & brstr &_
"<Username>" & username & "</username>" & brstr &_
"<Fromwhere>" & fromwhere & "</fromwhere>" & brstr &_
"<Posttime>" & posttime & "</posttime>" & brstr &_
"<Homepage>" & homepage & ""<Email>" & Email & "</Email>" & brstr &_
"<Text>" & text & "</text>" & brstr &_
"</List>" & CHR (13)
'Create an XML Segment Based on the obtained data
Set objxml2 = server. Createobject ("Microsoft. xmldom ")
'Create a New XML Object
Objxml2.loadxml (xmlnode)
'Read XML snippets into memory
Set rootnewnode1_objxml2.doc umentelement
'Get the root node of objxml2
Objrootlist. appendchild (rootnewnode)
'Insert XML fragments into list. xml
Objxml. Save (strsourcefile)
'Store the lsit. xml file (because list. XML is not stored and only updated in memory)
Set objxml = nothing
Set objxml2 = nothing
Response. Redirect ("index. asp ")
Response. End
End if
%>
<HTML>
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312">
<Meta name = "author" content = "Promise, xunuo">
<Title> Web desktop (XML message board )-
Http://www.xunuo.net </title>
<Script language = "JavaScript" src = "other. js"> </SCRIPT>
<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 = "# ffffff">
<Form action = "postnew. asp" method = "Post" name = "form1">
<Tr bgcolor = "#000000" type = "codeph" text = "/codeph">
<TD colspan = "2"> <font color = "# ffffff"> new message </font> </TD>
</Tr>
<Tr bgcolor = "# efefef">
<TD width = "19%" align = "right"> last name: </TD>
& Lt; TD width = "81%" & gt;
<Input type = "text" name = "username">
** </TD>
</Tr>
<Tr bgcolor = "# efefef">
<TD width = "19%" align = "right"> from: </TD>
& Lt; TD width = "81%" & gt;
<Input type = "text" name = "fromwhere" value = "China">
</TD>
</Tr>
<Tr bgcolor = "# efefef">
<TD width = "19%" align = "right"> main page: </TD>
& Lt; TD width = "81%" & gt;
<Input type = "text" name = "Homepage" value = "http: //">
</TD>
</Tr>
<Tr bgcolor = "# efefef">
<TD width = "19%" align = "right"> Email: </TD>
& Lt; TD width = "81%" & gt;
<Input type = "text" name = "email">
</TD>
</Tr>
<Tr bgcolor = "# efefef">
<TD width = "19%" align = "right" valign = "TOP"> content: </TD>
& Lt; TD width = "81%" & gt;
<Textarea name = "text" Cols = "60" rows = "10"> </textarea>
</TD>
</Tr>
<Tr bgcolor = "# efefef">
& Lt; TD width = "19%" align = "right" & gt; & lt;/TD & gt;
& Lt; TD width = "81%" & gt;
<Input type = "Submit" name = "Submit" value = "Submit">
<Input type = "reset" name = "submit2" value = "Refill">
</TD>
</Tr>
</Form>
</Table>
</Body>
</Html>
========================================================== ========================================================== ==========
Postedit. asp edit message content

<%
Dim ID, Action
Id = request. querystring ("ID ")
If isnumeric (ID) = false or isnull (ID) then
Response. Write ("the parameter is incorrect. Please return it! ")
Response. End
End if
Action = request. querystring ("action ")
Id = ID
If action = "Update" then
Id = request ("ID ")
Username = request. Form ("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"
'Obtain the path of the XML file. The path varies depending on your virtual directory.
Set objxml = server. Createobject ("Microsoft. xmldom ")
'Create an XML Object
Objxml. Load (strsourcefile)
'Read XML files into memory
Set objrootlist = objxml.doc umentelement. selectsinglenode ("newlist ")
'Select the <newlist> node

Set rootoldnode = objrootlist. childnodes. Item (ID)
'-------- New Start -----------
Brstr = CHR (13) & CHR (10) & CHR (9)
Xmlnode = brstr & "<list>" & brstr &_
"<ID>" & ID & "</ID>" & brstr &_
"<Username>" & username & "</username>" & brstr &_
"<Fromwhere>" & fromwhere & "</fromwhere>" & brstr &_
"<Posttime>" & posttime & "</posttime>" & brstr &_
"<Homepage>" & homepage & ""<Email>" & Email & "</Email>" & brstr &_
"<Text>" & text & "</text>" & brstr &_
"</List>" & CHR (13)
'Create an XML Segment Based on the obtained data
Set objxml2 = server. Createobject ("Microsoft. xmldom ")
'Create a New XML Object
Objxml2.loadxml (xmlnode)
'Read XML snippets into memory
Set rootnewnode1_objxml2.doc umentelement
'============ New ==========
Objrootlist. replaceChild rootnewnode, rootoldnode
Objxml. Save (strsourcefile)
Set objxml = nothing
Set objxml2 = nothing
Response. Redirect ("index. asp ")
Response. End
Else
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. xmldom ")
'Create an XML Object
Objxml. Load (strsourcefile)
'Read XML files into memory
Set objrootsite = objxml.doc umentelement. selectsinglenode ("newlist ")
'Select the <newlist> node
'Response. Write objrootsite. childnodes. Item (ID). childnodes. Item (1). Text
'Response. End
Id = objrootsite. childnodes. Item (ID). childnodes. Item (0). Text
'Id No.
Username = objrootsite. childnodes. Item (ID). childnodes. Item (1). Text
'Get Username
Fromwhere = objrootsite. childnodes. Item (ID). childnodes. Item (2). Text
'Get the user from there
Posttime = objrootsite. childnodes. Item (ID). childnodes. Item (3). Text
'Get message time
Homepage = objrootsite. childnodes. Item (ID). childnodes. Item (4). Text
'Get user Homepage
Email = objrootsite. childnodes. Item (ID). childnodes. Item (5). Text
'Get user eamil
TEXT = objrootsite. childnodes. Item (ID). childnodes. Item (6). Text
Set objxml = nothing
End if
%>

<HTML>
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312">
<Meta name = "author" content = "Promise, xunuo">
<Title> Web desktop (XML message board )-
Http://www.xunuo.net </title>
<Script language = "JavaScript" src = "other. js"> </SCRIPT>
<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 = "# ffffff">
<Form action = "postedit. asp? Action = Update "method =" Post "name =" form1 ">
<Input type = "hidden" value = "<% = ID %>" name = "ID"/>
<Tr bgcolor = "#000000" type = "codeph" text = "/codeph">
<TD colspan = "2"> <font color = "# ffffff"> new message </font> </TD>
</Tr>
<Tr bgcolor = "# efefef">
<TD width = "19%" align = "right"> last name: </TD>
& Lt; TD width = "81%" & gt;
<Input type = "text" name = "username" value = "<% = username %>">
** </TD>
</Tr>
<Tr bgcolor = "# efefef">
<TD width = "19%" align = "right"> from: </TD>
& Lt; TD width = "81%" & gt;
<Input type = "text" name = "fromwhere" value = "<% = fromwhere %>">
</TD>
</Tr>
<Tr bgcolor = "# efefef">
<TD width = "19%" align = "right"> main page: </TD>
& Lt; TD width = "81%" & gt;
<Input type = "text" name = "Homepage" value = "<% = homepage %>">
</TD>
</Tr>
<Tr bgcolor = "# efefef">
<TD width = "19%" align = "right"> Email: </TD>
& Lt; TD width = "81%" & gt;
<Input type = "text" name = "email" value = "<% = Email %>">
</TD>
</Tr>
<Tr bgcolor = "# efefef">
<TD width = "19%" align = "right" valign = "TOP"> content: </TD>
& Lt; TD width = "81%" & gt;
<Textarea name = "text" Cols = "60" rows = "10"> <% = text %> </textarea>
</TD>
</Tr>
<Tr bgcolor = "# efefef">
& Lt; TD width = "19%" align = "right" & gt; & lt;/TD & gt;
& Lt; TD width = "81%" & gt;
<Input type = "Submit" name = "Submit" value = "Submit">
<Input type = "reset" name = "submit2" value = "Refill">
</TD>
</Tr>
</Form>
</Table>
</Body>
</Html>

========================================================== ==================
Listxml. xml file

<? XML version = "1.0" encoding = "gb2312"?>
<Site>
<Newlist>
<List>
<ID> 0 </ID>
<Username> promise </username>
<Fromwhere> Hubei, China </fromwhere>
<Posttime> 10:12:42 </posttime>
<Homepage> http://www.xunuo.net/<Email> lffxunuo@163.com </Email>
<Text> new ASP + XML message board. Corrected the error in editing the previous version. </Text>
</List>
<List>
<List>
<ID> 5 </ID>
<Username> eeee name </username>
<Fromwhere> China </fromwhere>
<Posttime> 16:01:47 </posttime>
<Homepage> http: // <Email> Email: </Email>
<Text> content: </text>
</List>
<List>
<ID> 6 </ID>
<Username> new message </username>
<Fromwhere> China </fromwhere>
<Posttime> 16:02:42 </posttime>
<Homepage> http: // <Email> Email: </Email>
<Text> content: </text>
</List>
</Newlist>
</Site>

Related 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.