Use Asp+xml to create message book-3

Source: Internet
Author: User
Tags chr insert
Asp+|xml use Asp+xml to create a message book-3
(01-6-6 15)

Vi. establishment of a new message program (postnew.asp)

The function of this file is to write a new XML node, first create an XML image and then read the XML into memory, using the AppendChild () method
Join the XML node we generated.

<%
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"
' Get the path to the XML file, which is different depending on your virtual directory.
Set objxml = Server.CreateObject ("Microsoft.XMLDOM")
' Create an XML pair like
Objxml.load (strSourceFile)
' Read the XML file into memory
Set objrootlist = ObjXML.documentElement.selectSingleNode ("NewList")
' Select the <NewList> node
If Objrootlist.haschildnodes Then
' To determine if <NewList> has child nodes (because if it is every time <NewList> is not a child node,
' If you don't make a judgment, you'll get an error at the first time.
id = objrootlist.lastchild.firstchild.text+1
' Here gets the ID number of the child node that will be inserted, with the first child node of the last child node (LastChild) whose ID number is <NewList> (firstchild)
ID number plus 1 (here we increment according to the ID number of the relational database)
Else
' If no word child node is the first time message ID number set to 1
Id=1
End If
BRSTR=CHR (&AMP;CHR) &AMP;CHR (9)
' To insert the nodes in the XML file to line up lines of space
' (Of course you can not do this just for the sake of XML data.)
xmlnode=brstr& "<list>" &brstr & _
"<id>" &id& "</id>" &brstr & _
"<username>" &username& "</username>" &brstr & _
"<fromwhere>" &fromwhere& "</fromwhere>" &brstr & _
"<Posttime>" &Posttime& "</Posttime>" &brstr & _
""<email>" &email& "</email>" &brstr & _
"<text>" &text& "</text>" &brstr & _
"</list>" &AMP;CHR (13)
' Create an XML fragment based on the resulting data
Set Objxml2=server.createobject ("Microsoft.XMLDOM")
' Create a new XML pair like
Objxml2.loadxml (XMLnode)
' Read the XML fragment into memory
Set Rootnewnode=objxml2.documentelement
' Get the root node of objXML2
Objrootlist.appendchild (Rootnewnode)
' Insert the XML fragment into the List.xml
Objxml.save (strSourceFile)
' Store Lsit.xml file (because no storage list.xml is updated in memory only)
Set objxml=nothing
Set objxml2=nothing
Response.Write "Thank you for your message."
Response.End

End If
%>
<title> Untitled Document </title>
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 ">
<style type= "Text/css"
!--
td {FONT-SIZE:9PT}
-->
</style>
<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" >
<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>
<TD width= "81%" >
<input type= "text" name= "Fromwhere" value= "China"
</td>
</tr>
<TR bgcolor= "#EFEFEF" >
<TD width= "19%" align= "right" homepage: </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= "text" name= "email"
</td>
</tr>
<TR bgcolor= "#EFEFEF" >
<TD width= "19%" align= "right" valign= "Top" "Content: </td>
<TD width= "81%" >
<textarea name= "text" cols= "a" rows= "ten" > </textarea>
</td>
</tr>
<TR bgcolor= "#EFEFEF" >
<TD width= "19%" align= "right" > </td>
<TD width= "81%" >
<input type= "Submit" name= "Submission" value= "submitted"
<input type= "reset" name= "Submit2" value= "refill"
</td>
</tr>
</form>
</table>
</body>



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.