主题:写入xml文件时出错
我想做一个网上投票系统,采用的是xml存储数据的方式。我的vote.xml文件如下:
<?xml version="1.0" encoding="gb2312">
<newvote>
<vote>
<allvote></allvote>
<verygood></verygood>
<good></good>
<nomal></nomal>
<bad></bad>
</vote>
</newvote>
asp.net页面(vote.aspx)代码如下:
<%@ import namespace="system.xml"%>
<%@ import namespace="system.data.oledb" %>
<%@ import namespace="system.data" %>
<%@ Page Language="VB" debug="true" ContentType="text/html"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>
<script runat="server">
Sub user_vote(sender As Object, E As commandeventargs)
dim voteds as dataset=new dataset()
voteds.readxml(server.MapPath("image\vote.xml"))
voteds.tables(0).rows(0).item(0)+=1
select case radio1.selecteditem.value
case "1"
voteds.tables(0).rows(0).item(1)+=1
case "2"
voteds.tables(0).rows(0).item(2)+=1
case "3"
voteds.tables(0).rows(0).item(3)+=1
case "4"
voteds.tables(0).rows(0).item(4)+=1
end select
voteds.writexml(server.MapPath("image\vote.xml"))
votelabel.style("color")="red"
votelabel.text="投票成功!"
End Sub
</script>
<body>
<form runat="server">
<table align="center">
<tr><td align="center">网站调查</td></tr>
<tr><td>你觉得这个站点怎么样</td></tr>
<tr><td>
<asp:RadioButtonList ID="radio1" runat="server">
<asp:listitem Value="1" selected>很好</asp:listitem>
<asp:listitem value="2">好</asp:listitem>
<asp:listitem value="3">一般</asp:listitem>
<asp:listitem Value="4">差</asp:listitem>
</asp:RadioButtonList>
</td></tr>
<tr><td><br></td></tr>
<tr><td align="center"><asp:Button ID="toupiao" runat="server" commandname="vote123" Text="投票" oncommand="user_vote"/><asp:Button ID="chakan" runat="server" Text="查看" /></td></tr>
<tr>
<td align="center"><asp:label id="votelabel" runat="server"></asp:label></td>
</tr>
</table>
</form>
</body>
</html>
出错信息如下:
Server Error in '/' Application.
--------------------------------------------------------------------------------
This is an unexpected token. The expected token is 'NAME'. Line 1, position 38.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Xml.XmlException: This is an unexpected token. The expected token is 'NAME'. Line 1, position 38.
Source Error:
Line 12: Sub user_vote(sender As Object, E As commandeventargs)
Line 13: dim voteds as dataset=new dataset()
Line 14: voteds.readxml(server.MapPath("image\vote.xml"))
Line 15: voteds.tables(0).rows(0).item(0)+=1
Line 16: select case radio1.selecteditem.value
代码太多了,请大家帮我看一看吧,小弟感谢不尽。
<?xml version="1.0" encoding="gb2312">
<newvote>
<vote>
<allvote></allvote>
<verygood></verygood>
<good></good>
<nomal></nomal>
<bad></bad>
</vote>
</newvote>
asp.net页面(vote.aspx)代码如下:
<%@ import namespace="system.xml"%>
<%@ import namespace="system.data.oledb" %>
<%@ import namespace="system.data" %>
<%@ Page Language="VB" debug="true" ContentType="text/html"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>
<script runat="server">
Sub user_vote(sender As Object, E As commandeventargs)
dim voteds as dataset=new dataset()
voteds.readxml(server.MapPath("image\vote.xml"))
voteds.tables(0).rows(0).item(0)+=1
select case radio1.selecteditem.value
case "1"
voteds.tables(0).rows(0).item(1)+=1
case "2"
voteds.tables(0).rows(0).item(2)+=1
case "3"
voteds.tables(0).rows(0).item(3)+=1
case "4"
voteds.tables(0).rows(0).item(4)+=1
end select
voteds.writexml(server.MapPath("image\vote.xml"))
votelabel.style("color")="red"
votelabel.text="投票成功!"
End Sub
</script>
<body>
<form runat="server">
<table align="center">
<tr><td align="center">网站调查</td></tr>
<tr><td>你觉得这个站点怎么样</td></tr>
<tr><td>
<asp:RadioButtonList ID="radio1" runat="server">
<asp:listitem Value="1" selected>很好</asp:listitem>
<asp:listitem value="2">好</asp:listitem>
<asp:listitem value="3">一般</asp:listitem>
<asp:listitem Value="4">差</asp:listitem>
</asp:RadioButtonList>
</td></tr>
<tr><td><br></td></tr>
<tr><td align="center"><asp:Button ID="toupiao" runat="server" commandname="vote123" Text="投票" oncommand="user_vote"/><asp:Button ID="chakan" runat="server" Text="查看" /></td></tr>
<tr>
<td align="center"><asp:label id="votelabel" runat="server"></asp:label></td>
</tr>
</table>
</form>
</body>
</html>
出错信息如下:
Server Error in '/' Application.
--------------------------------------------------------------------------------
This is an unexpected token. The expected token is 'NAME'. Line 1, position 38.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Xml.XmlException: This is an unexpected token. The expected token is 'NAME'. Line 1, position 38.
Source Error:
Line 12: Sub user_vote(sender As Object, E As commandeventargs)
Line 13: dim voteds as dataset=new dataset()
Line 14: voteds.readxml(server.MapPath("image\vote.xml"))
Line 15: voteds.tables(0).rows(0).item(0)+=1
Line 16: select case radio1.selecteditem.value
代码太多了,请大家帮我看一看吧,小弟感谢不尽。