5. Program home page (default.asp)
??Call the corresponding include files and public functions to format the XML file and display it. As you can see, the page Title is customizable, and the public header and trailer are made into corresponding include files. C_TITLE, C_XMLFILE and C_XSLFILE are public constants, defined in the constpub.asp file. As for their meanings, I believe readers can easily understand them. The FormatXml function defined above is called here. <% Option Explicit '********************************************** 'Description: Address book ' Author: gwd 2002-11-05 '********************************************** %> <!--#include file="pub/funcxml.asp"--> <!--#include file="pub/constpub.asp"--> <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"> </HEAD> <BODY> <!--#include file="pub/header.asp"--> <% = FormatXml(C_XMLFILE, C_XSLFILE) %> <br> <!--#include file="pub/footer.asp"--> </BODY> </HTML> |
6. Add, modify and delete information in XML
??We know that the corresponding method has been defined in Cls_Person, so in each file, we only need to call the corresponding method. The file for adding information is add.asp, the file for modifying information is edit.asp, and the file for deleting information is delete.asp. We only take the add.asp file as an example for explanation. 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 ' Generate Cls_Person object If Request.Form("btnOk") <> "" Then If LoadXmlDoc(objXml, C_XMLFILE, False, strErr) Then 'Load XML file' Assign value to the corresponding attribute 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 ' Call the AddToXml method of the Cls_Person class to add data AddErr strErr, objPerson.GetLastError Else AddErr strErr, "Add successfully" 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" onsubmit="return CheckForm()"> <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="25" 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="25" class="input" value="<%=CheckStrOutput(objPerson.Nick)%>"></td> </tr> <tr bgcolor="#ffffff"> <td bgcolor="#e5e5e5" align="right"><b>Mobile phone: </b></td> <td><input type="text" name="txtMobile" size="25" 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="25" 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="25" 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="25" 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="25" class="input" value="<%=CheckStrOutput(objPerson.Company)%>"></td> </tr> </table> <br> <div align="center"> <input type="submit" name="btnOk" value="Submit"> <input type="button" name="btnClose" value="Close" onclick="javascript:return window.close();"> </div> </form> </BODY> </HTML> <% Set objPerson = Nothing %> |
7. Summary
??At this point, our contact information management program is complete. How it goes, how it feels, it should be quite simple. Of course, there are still many areas for improvement in this routine, and I am just giving some ideas here. I hope readers can modify and improve it themselves after mastering XML programming.
??This routine has been tested on my local machine (Windows Server 2000, IIS5.0 and IE6.0) and on the Internet, and it can run normally.
Click to download the source code of this article