我想通过一个aspx页面来实现修改xml里面数据。//xml
<?xml version="1.0"?>
  <admin>
    <name>admin</name>
    <password>admin0</password>
 </admin>
//aspx
<%@ Page Language="C#" ContentType="text/html" ResponseEncoding="utf-8" %>
<!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=utf-8" />
<title>无标题文档</title>
</head><body><script language="c#" runat="server">
using System;   
using System.Xml;
using System.Xml.XPath;
using System.Data;  
 
protect void Page_Load(object sender,EventArgs e)
{
XmlDocument xmlDoc=new XmlDocument();   
xmlDoc.Load(Server.MapPath("~/data.xml"));  
XmlNode root = xmlDoc.DocumentElement;
XmlNode name = root.SelectSingleNode("name");
name.InnerText = "mnm";
xmlDoc.Save(Server.MapPath("~/data.xml"));
}
    
</script></body>
</html>
结果在vs2008里,aspx编译有错如下。
错误 2 类、结构或接口成员声明中的标记“;”无效 d:\我的文档\桌面\myweb\default.aspx 12 13 d:\...\myweb\
错误 3 类、结构或接口成员声明中的标记“;”无效 d:\我的文档\桌面\myweb\default.aspx 13 17 d:\...\myweb\
错误 4 类、结构或接口成员声明中的标记“;”无效 d:\我的文档\桌面\myweb\default.aspx 14 23 d:\...\myweb\
错误 5 类、结构或接口成员声明中的标记“;”无效 d:\我的文档\桌面\myweb\default.aspx 15 18 d:\...\myweb\
错误 1 类、结构或接口成员声明中的标记“using”无效 d:\我的文档\桌面\myweb\default.aspx 12 1 d:\...\myweb\
错误 6 类、结构或接口成员声明中的标记“void”无效 d:\我的文档\桌面\myweb\default.aspx 16 9 d:\...\myweb\
错误 7 意外的 XML 声明。XML 声明必须是文档中的第一个节点,而且声明前面不允许出现空白字符。 d:\我的文档\桌面\myweb\data.xml 2 3 d:\...\myweb\

解决方案 »

  1.   

    引用命名空间错误了吧.
    <%@ import Namespace="System" %>
    <%@ import Namespace="System.Xml"%>
      

  2.   

    using System;   
    using System.Xml;
    using System.Xml.XPath;
    using System.Data;   
     
    protect void Page_Load(object sender,EventArgs e)
    {
    XmlDocument xmlDoc=new XmlDocument();   
    xmlDoc.Load(Server.MapPath("~/data.xml"));   
    XmlNode root = xmlDoc.DocumentElement;
    XmlNode name = root.SelectSingleNode("name");
    name.InnerText = "mnm";
    xmlDoc.Save(Server.MapPath("~/data.xml"));
    }
    这些你写前台了?