V. Program homepage (default.asp)
Call the corresponding include file and public function, format the XML file, and display it. As you can see, the title of the page is customizable, and the public head and tail are made up of the corresponding include files. C_title, C_xmlfile, and c_xslfile are common constants, defined in constpub.asp files, and as far as their meaning is concerned, readers can easily understand them. This invokes the Formatxml function defined above.
<% Option Explicit '*********************************************** ' Description: Address Book ' Author: gwd 2002-11-05 '*********************************************** %> !--#include file= "pub/funcxml.asp"--> !--#include file= "pub/constpub.asp"-->
<% = C_title%>
!--#include file= "pub/header.asp"--> <% = Formatxml (C_xmlfile, C_xslfile)%>
!--#include file= "pub/footer.asp"-->
|
Vi. adding, modifying, and deleting information in XML
We know that the corresponding method has been defined in the Cls_person, so in each file, you just need to call the corresponding method. The file to add the information is add.asp, the file that modifies the information is edit.asp, the file that deletes the information is delete.asp, we only take add.asp file as an example to explain. The Checkstrinput and Checkstroutput functions are used to format the user's input and output strings.
<% Option Explicit '*********************************************** ' Description: 37080308 Address Book ' Author: gwd 2002-11-05 '*********************************************** %> !--#include file= "pub/funcxml.asp"--> !--#include file= "pub/constpub.asp"--> !--#include file= "pub/funcpub.asp"--> !--#include file= "pub/class/clsperson.asp"--> <% Dim Objxml, Objperson Dim Strerr Set objxml = Server.CreateObject ("MSXML2. DOMDocument ") Set Objperson = New Cls_person ' generates Cls_person object If Request.Form ("Btnok") <> "Then If Loadxmldoc (Objxml, C_xmlfile, False, strerr) Then ' Load XML file ' Assign a value to the corresponding property Objperson.name = Checkstrinput (Request.Form ("txtname")) Objperson.nick = Checkstrinput (Request.Form ("Txtnick")) Objperson.mobile = Checkstrinput (Request.Form ("Txtmobile")) Objperson.tel = Checkstrinput (Request.Form ("Txttel")) Objperson.email = Checkstrinput (Request.Form ("Txtemail")) OBJPERSON.QQ = Checkstrinput (Request.Form ("TXTQQ")) Objperson.company = Checkstrinput (Request.Form ("Txtcompany")) If not Objperson.addtoxml (objxml) Then ' invokes the Addtoxml method of the Cls_person class, adding data Adderr Strerr, Objperson.getlasterror Else Adderr Strerr, "add Success" Response.Write "<script language=" "JavaScript" >opener.location.reload (); </script> End If End If End If Set Objxml = Nothing %> <HTML> <HEAD> <TITLE> <% = C_title%> </TITLE> <meta http-equiv= "Content-type" content= "text/html;charset=gb2312" <link rel= "stylesheet" href= "Contact.css" type= "Text/css" <script language= "JavaScript" > !-- function Checkform () { return true; } --> </script> </HEAD> <BODY> <% = Strerr%> <div class= "title" Add contact information </div> <form name= "Form1" method= "Post" action= "add.asp" <table align= "center" width= "100%" cellspacing= "1" cellpadding= "2" border= "0" bgcolor= "#666600" <TR bgcolor= "#ffffff" > <TD width= "25%" bgcolor= "#e5e5e5" align= "right" <b> Name: </b> </td> <TD width= "75%" ><input type= "text" name= "txtname" size= "" class= "input" value= "<%=checkstroutput (objperson.name)%> "> </td> </tr> <TR bgcolor= "#ffffff" > <TD bgcolor= "#e5e5e5" align= "right" > <b> English name: </b> </td> <td> <input type= "text" name= "Txtnick" size= "" class= "input" value= "<%=checkstroutput (Objperson.nick)%>" > </td> </tr> <TR bgcolor= "#ffffff" > <TD bgcolor= "#e5e5e5" align= "right" > <b> Mobile: </b> </td> <td> <input type= "text" name= "Txtmobile" size= "" class= "input" value= "<%=checkstroutput (objperson.mobile)%>" > </td> </tr> <TR bgcolor= "#ffffff" > <TD bgcolor= "#e5e5e5" align= "Right" <b> Tel: </b> </td> <td> <input type= "text" name= "Txttel" size= "" class= "input" value= "<%=checkstroutput (Objperson.tel)%>" > </td> </tr> <TR bgcolor= "#ffffff" > <TD bgcolor= "#e5e5e5" align= "right" > <b> Email: </b> </td> <td> <input type= "text" name= "Txtemail" size= "" class= "input" value= "<%=checkstroutput (objperson.email)%>" > </td> </tr> <TR bgcolor= "#ffffff" > <TD bgcolor= "#e5e5e5" align= "right" > <b> QQ: </b> </td> <td> <input type= "text" name= "txtqq" size= "" class= "input" value= "<%=checkstroutput (OBJPERSON.QQ)%>" > </td> </tr> <TR bgcolor= "#ffffff" > <TD bgcolor= "#e5e5e5" align= "right" > <b> Company: </b> </td> <td> <input type= "text" name= "Txtcompany" size= "" class= "input" value= "<%=checkstroutput (objperson.company)%>" ></ td> </tr> </table> <br> <div align= "Center" <input type= "Submit" Name= "Btnok" value= "Submission" <input type= "button" Name= "Btnclose" value= "Off" </div> </form> </BODY> </HTML> <% Set Objperson = Nothing %> |
Vii. Summary
To this, our contact information management program is done. How, how it feels, it should be quite simple. Of course, this routine has a lot to improve the place, I am here is just a good point, I hope that the reader in the Master of XML programming, modify their own perfect bar.
This routine has been tested on my own computer (Windows Server 2000, IIS5.0, and IE6.0) and on the web, and it works correctly.
Click to Download the source code of this article