主题:  请帮忙改错!!!!

jiahui

职务:普通成员
等级:1
金币:0.0
发贴:5
#12005/4/6 16:02:45
本程序为留言版

c:\inetpub\wwwroot\WebApplication3\WebForm1.aspx.cs(11): 找不到类型或命名空间名称“XmlDocument”(是否缺少 using 指令或程序集引用?)

问题是c:\inetpub\wwwroot\WebApplication3\WebForm1.aspx.cs(12): 找不到类型或命名空间名称“xdoc”(是否缺少 using 指令或程序集引用?)



using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using XmlDocument;
using xdoc;


namespace WebApplication3
{
    /// <summary>
    /// WebForm1 的摘要说明。
    /// </summary>
    public class WebForm1 : System.Web.UI.Page
    {
        protected System.Web.UI.WebControls.TextBox TextBox1;
        protected System.Web.UI.WebControls.Label Label2;
        protected System.Web.UI.WebControls.Label Label3;
        protected System.Web.UI.WebControls.Label Label4;
        protected System.Web.UI.WebControls.TextBox TextBox2;
        protected System.Web.UI.WebControls.Label Label5;
        protected System.Web.UI.WebControls.Label Label6;
        protected System.Web.UI.WebControls.TextBox TextBox3;
        protected System.Web.UI.WebControls.Label Label7;
        protected System.Web.UI.WebControls.TextBox TextBox4;
        protected System.Web.UI.WebControls.Label Label8;
        protected System.Web.UI.WebControls.Button Button1;
        protected System.Web.UI.WebControls.Button Button2;
        protected System.Web.UI.WebControls.Button Button3;
        protected System.Web.UI.WebControls.Label Label1;
    
        private void Page_Load(object sender, System.EventArgs e)
        {
            
            // 创建一个XmlDocument对象以载入存储信息的XML文件
            XmlDocument xdoc = new XmlDocument();
            xdoc.Load( Server.MapPath( "guestbook.xml" ));

            // 创建一个XslTransform对象并导入XSL文件
            XslTransform xslt = new XslTransform();
            xslt.Load( Server.MapPath( "guestbook.xsl" ));

            string xmlQuery = "//guestbook";
            XmlNodeList nodeList = xdoc.DocumentElement.SelectNodes( xmlQuery );

            MemoryStream ms = new MemoryStream();
            xslt.Transform( xdoc, null, ms );
            ms.Seek( 0, SeekOrigin.Begin );

            StreamReader sr = new StreamReader( ms );

            // 显示输出结果
            Response.Write( sr.ReadToEnd() );
        }
        private void SaveXMLData()
        {
            try
            {
                // 创建一个XmlDocument对象,用于载入存储信息的XML文件
                XmlDocument xdoc = new XmlDocument();
                xdoc.Load( Server.MapPath( "guestbook.xml" ));

                // 创建一个新的guest节点并将它添加到根节点下
                XmlElement parentNode = xdoc.CreateElement( "guest" );
                xdoc.DocumentElement.PrependChild( parentNode );

                // 创建所有用于存储信息的节点
                XmlElement nameNode = xdoc.CreateElement( "name" );
                XmlElement emailNode = xdoc.CreateElement( "email" );
                XmlElement qqNode = xdoc.CreateElement( "qq" );
                XmlElement homepageNode = xdoc.CreateElement( "homepage" );
                XmlElement commentNode = xdoc.CreateElement( "comment" );

                // 获取文本信息
                XmlText nameText = xdoc.CreateTextNode( name.Text );
                XmlText emailText = xdoc.CreateTextNode( email.Text );
                XmlText qqText = xdoc.CreateTextNode( qq.Text );
                XmlText homepageText = xdoc.CreateTextNode( homepage.Text );
                XmlText commentText = xdoc.CreateTextNode( comment.Text );

                // 将上面创建的各个存储信息的节点添加到guest节点下但并不包含最终的值
                parentNode.AppendChild( nameNode );
                parentNode.AppendChild( emailNode );
                parentNode.AppendChild( qqNode );
                parentNode.AppendChild( homepageNode );
                parentNode.AppendChild( commentNode );

                // 将上面获取的文本信息添加到与之相对应的节点中
                nameNode.AppendChild( nameText );
                emailNode.AppendChild( emailText );
                qqNode.AppendChild( qqText );
                homepageNode.AppendChild( homepageText );
                commentNode.AppendChild( commentText );

                // 保存存储信息的XML文件
                xdoc.Save( Server.MapPath( "guestbook.xml" ));

                // 显示所有用户的留言信息
                Response.Redirect( "ViewGuestBook.aspx" );
            }
            catch( Exception e ) {}
        }
        private void btnOK_Click(object sender, System.EventArgs e)
        {
            SaveXMLData();

            name.Text = "";
            email.Text = "";
            qq.Text = "";
            homepage.Text = "";
            comment.Text = "";
        }

        private void btnReset_Click(object sender, System.EventArgs e)
        {
            name.Text = "";
            email.Text = "";
            qq.Text = "";
            homepage.Text = "";
            comment.Text = "";
        }

        private void btnView_Click(object sender, System.EventArgs e)
        {
            // 显示所有用户的留言信息
            Response.Redirect( "ViewGuestBook.aspx" );
        }









        #region Web 窗体设计器生成的代码
        override protected void OnInit(EventArgs e)
        {
            //
            // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
            //
            InitializeComponent();
            base.OnInit(e);
        }
        
        /// <summary>
        /// 设计器支持所需的方法 - 不要使用代码编辑器修改
        /// 此方法的内容。
        /// </summary>
        private void InitializeComponent()
        {
            this.Load += new System.EventHandler(this.Page_Load);

        }
        #endregion
    }
}