5. Program homepage ()
Call the corresponding containing files and public functions, format the XML file, and display it. As you can see, the page Title is customizable, and the common head and tail are made into corresponding inclusion files. C_TITLE, C_XMLFILE and C_XSLFILE are common constants and are defined in files. As for their meaning, I believe readers can easily understand it. The FormatXml function defined above is called here.
<% Option Explicit
'***********************************************
' Instructions: Address Book
' Author: gwd 2002-11-05
'***********************************************
%>
<!--#include file="pub/"-->
<!--#include file="pub/"-->
<HTML>
<HEAD>
<TITLE><% = C_TITLE %></TITLE>
<META HTTP-EQUIV="content-type" CONTENT="text/html;charset=GB2312"/>
<link rel="stylesheet" href="" type="text/css">
</HEAD>
<BODY>
<!--#include file="pub/"-->
<% = FormatXml(C_XMLFILE, C_XSLFILE) %>
<br>
<!--#include file="pub/"-->
</BODY>
</HTML>
6. Add, modify and delete information in XML
We know that the corresponding methods have been defined in Cls_Person, so in each file, you only need to call the corresponding methods. The file that adds information is, the file that modifys information is, and the file that deletes information is, we will only use the file as an example to illustrate. The CheckStrInput and CheckStrOutput functions are used to format the user's input and output strings.
<% Option Explicit
'***********************************************
' Instructions: 37080308 Address Book
' Author: gwd 2002-11-05
'***********************************************
%>
<!--#include file="pub/"-->
<!--#include file="pub/"-->
<!--#include file="pub/"-->
<!--#include file="pub/class/"-->
<%
Dim objXml, objPerson
Dim strErr
Set objXml = ("")
Set objPerson = New Cls_Person ' Generate Cls_Person object
If ("btnOk") <> "" Then
If LoadXmlDoc(objXml, C_XMLFILE, False, strErr) Then ' Load XML file
'Assign values to the corresponding attribute
= CheckStrInput(("txtName"))
= CheckStrInput(("txtNick"))
= CheckStrInput(("txtMobile"))
= CheckStrInput(("txtTel"))
= CheckStrInput(("txtEmail"))
= CheckStrInput(("txtQQ"))
= CheckStrInput(("txtCompany"))
If Not (objXml) Then ' Calling the AddToXml method of the Cls_Person class to add data
AddErr strErr,
Else
AddErr strErr, "Added Successfully"
"<script language=""javascript"">();</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="" 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="" 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()%>"></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()%>"></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()%>"></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()%>"></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()%>"></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()%>"></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()%>"></td>
</tr>
</table>
<br>
<div align="center">
<input type="submit" name="btnOk" value="submit">
<input type="button" name="btnClose" value="Close" onclick="javascript:return ();">
</div>
</form>
</BODY>
</HTML>
<%
Set objPerson = Nothing
%>
7. Summary
At this point, our contact information management program is done. How it feels, it should be quite simple. Of course, there are many things that can be improved in this routine, and I am just a throwaway here. I hope that readers will modify and improve it by themselves after mastering XML programming.
This routine has been tested on my local machine (Windows Server 2000, IIS5.0, and IE6.0) and online, and it works normally.