viewpost.aspx--察看提交的留言
viewguestbook.aspx--察看所有留言
header.inc
guestpost.aspx--留言表单及xml写操作
footer.inc
guest.xml--xml数据
源代码如下:
viewguestbook.aspx
<%@ import namespace="system" %>
<%@ import namespace="system.io" %>
<%@ import namespace="system.data" %>
<%@ assembly name="system.xml" %>
<%@ import namespace="system.xml" %>
<%@ page language="c<%-- needed assembiles --%>
<html>
<head>
<title>welcome to saurabh's guestbook.</title>
<script language="c //run the script when the page is loaded
public void page_load(object sender, eventargs e)
{
// an label , its use stated later
tryagain :
//the path to the xml file which will contain all the data
//modify this if you have any other file or directory mappings.
//modify this if you have been directed here from step 2 of the readme file.
string datafile = "db/guest.xml" ;
//try-catch block to read from an xml file
try
{
//make an instance to the xmldatadocument class
//this class can read from an xml file in and ordered format
xmldatadocument datadoc = new xmldatadocument();
// infer the dataset schema from the xml data and load the xml data
datadoc.dataset.readxml(new streamreader(server.mappath(datafile)));
//databind the first table in the dataset to the repeter
mydatalist.datasource = datadoc.dataset.tables[0].defaultview;
mydatalist.databind();
//free up the xml file to be used by other programs
datadoc=null;
}
catch(ioexception ed)
{
// here i am for now trying to overcome a bug in my guestbook exapmle
//the bug is that only one class can either read or write to my xml
// data file at a time.
//if the file is being used my some some other page (eg the guest book viewing page)
// then an ioexception will be thrown
// so to handle such situtations what we do is that
// if an ioexception is thrown the page goes again to the tryagain label
//and tries to write again into the xml file
//this goes on till finally the resource is freed and the xml file is written to.
goto tryagain ;
}
catch (exception edd)
{
//catch any other exceptions that occur
errmess.text="cannot read from xml file because "+edd.tostring() ;
}
}
</script>
<link href="mystyle.css" type=text/css rel=stylesheet>
</head>
<body topmargin="0" leftmargin="0" marginwidth="0" marginheight="0" rightmargin="0">
<!-- <asp:label id="errmess" text="" style="color:<br>
<h3 align="center" class="newsbody">my guestbook.</h3>
<asp:repeater id="mydatalist" runat="server">
<template name="headertemplate">
<table class="mainheads" width="100%" style="font: 8pt verdana">
<tr style="background-color: <th>
name
</th>
<th>
country
</th>
<th>
email
</th>
<th>
comments
</th>
<th>
date/time
</th>
</tr>
</template>
<template name="itemtemplate">
<tr style="background-color: <td>
<% </td>
<td>
<% </td>
<td>
<% </td>
Java Asp PHP .Net XML C/C++ CGI VB Jsp J2ee J2se J2me EJB Servlet Tomcat Resin Struts Weblogic Eclipse ANT GUI JMS Web servise IDEA Webphere Hibernate Spring Jboss Applet Swing Socket Javamail Perl Ajax P2P 安全 模式 框架 测试 开源 游戏
Windows XP Windows 2000 Windows 2003 Windows Me Windows 9.x Linux UNIX 注册表 操作系统 服务器 应用服务器