如题。
找了找,好像应该用XmlTextWriter,但是XmlTextWriter只能输出到Console.out或者文件中。

解决方案 »

  1.   

    读到流里面,然后:
    System.IO.StreamReader _read=new System.IO.StreamReader(sdata.Request.InputStream);
    String str=_read.readtoend();
      

  2.   

    带格式的显示到文本框中可以用如下的方法:
    XmlDocument doc = new XmlDocument();
    doc.Load("xmlfile.xml");
    StringWriter writer1 = new StringWriter();
    XmlTextWriter writer2 = new XmlTextWriter(writer1);
    writer2.Formatting = Formatting.Indented;
    writer2.Indentation=1;
    writer2.IndentChar= '\t';
    doc.WriteTo(writer2);
    this.textBox1.Text = writer1.ToString();
      

  3.   

    我有一个例子就是把网站的常量CONST,放在XML文件当中,网站启动时加载。在后台可以维护重新写入XML文件当中。
    其中CONST.CS文件你看看,这个主要是载入。
    +++++++++++++++++++++++++++++++++++++++
    public class Const
    {
    public static string sitename="";
    public static string domain="";
    public static string webemail="";
    public static string weblogo="";
    public static string regtime="";
    public static string keywords="";
    public static string description="";
    public static string copyright="";
    public static string maxonline="";  //历史最高在线人数
    public static string onlinetime="";  //历史最高在线发生时间
    public static string isregister="";  //是否允许注册
    public static string minusername="";  //最短用户名长度
    public static string maxusername="";  // 最长用户名长度 
     static Const()
    {
    //
    // TODO: 在此处添加构造函数逻辑
    XmlDocument xmldoc=new XmlDocument();
    xmldoc.Load(System.Web.HttpContext.Current.Server.MapPath("/hbtd/SiteConst.xml"));     //装入XML文档
    XmlNodeReader reader=new XmlNodeReader(xmldoc); //读取
        XmlNode node=xmldoc.DocumentElement;
    if(reader.Read())
    {
    sitename=node["sitename"].InnerText;
                    domain=node["domain"].InnerText;
    webemail=node["webemail"].InnerText;
    regtime=node["regtime"].InnerText;
    weblogo=node["weblogo"].InnerText;
    keywords=node["keywords"].InnerText;
    description=node["description"].InnerText;
    copyright=node["copyright"].InnerText;

    }
    reader.Close();

    }

    }
    ++++++++++++++++++++++++++++++++++++++下面是后台维护,并包含了如何显示在TEXTBOX中的代码和重写XML文件的代码:
    ++++++++++++++++++++++++++++++++++++private void Page_Load(object sender, System.EventArgs e)
    {
    // 在此处放置用户代码以初始化页面
    this.t_sitename.Value=Const.sitename;
    this.t_weblogo.Value=Const.weblogo;
    this.t_webemail.Value=Const.webemail;
    this.t_keywords.Value=Const.keywords;
    this.t_domain.Value=Const.domain;
    this.t_description.Value=Const.description;
    this.t_copyright.Value=Const.copyright;
    this.t_maxonline.Value=Const.maxonline;
    this.t_maxusername.Value=Const.maxusername;
    this.t_minusername.Value=Const.minusername;
    this.t_onlinetime.Value=Const.onlinetime;
    if(Const.isregister=="1")
    {
    this.Radio2.Checked=true; }
    else
    {
    this.Radio1.Checked=true;
    }
    } #region Web 窗体设计器生成的代码
    override protected void OnInit(EventArgs e)
    {
    //
    // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
    //
    InitializeComponent();
    base.OnInit(e);
    }

    /// <summary>
    /// 设计器支持所需的方法 - 不要使用代码编辑器修改
    /// 此方法的内容。
    /// </summary>
    private void InitializeComponent()
    {    
    this.btn_update.Click += new System.EventHandler(this.btn_update_Click);
    this.Load += new System.EventHandler(this.Page_Load); }
    #endregion private void btn_update_Click(object sender, System.EventArgs e)
    {
    XmlDocument xmldoc=new XmlDocument();
    xmldoc.Load(System.Web.HttpContext.Current.Server.MapPath("../SiteConst.xml"));     //装入XML文档
    XmlNodeReader reader=new XmlNodeReader(xmldoc); //读取
    XmlNode node=xmldoc.DocumentElement;
    if(reader.Read())
    {
    node["sitename"].InnerText=Request["t_sitename"];
    node["domain"].InnerText=Request["t_domain"];
    node["webemail"].InnerText=Request["t_webemail"];
    node["weblogo"].InnerText=Request["t_weblogo"];
    node["keywords"].InnerText=Request["t_keywords"];
    node["description"].InnerText=Request["t_description"];
    node["copyright"].InnerText=Request["t_copyright"];
    node["maxonline"].InnerText=Request["t_maxonline"];
    node["maxusername"].InnerText=Request["t_maxusername"];
    node["minusername"].InnerText=Request["t_minusername"];
    node["onlinetime"].InnerText=Request["t_onlinetime"];
    if(this.Radio2.Checked==true)
    {
    node["isregister"].InnerText="1";
    }
    else
    {
                       node["isregister"].InnerText="0";
    }

    }
    xmldoc.Save(System.Web.HttpContext.Current.Server.MapPath("../SiteConst.xml"));
    reader.Close();
    Response.Write("<script>alert('修改成功!');window.location.href='main.aspx';</script>");

    }
    }我想对你会有帮助!!!