XmlTextWriter writer;
String filepath = Server.MapPath("xmlDocument.xml");
writer = new XmlTextWriter(filepath,Encoding.UTF8);

解决方案 »

  1.   

    这也是一个方法:
    XmlDocument doc = new XmlDocument();
    doc.LoadXml ("<?xml version='1.0' encoding='UTF8'?><document><title>"+title.Text +"</title><author>"+author.Text +"</author><otime>"+DateTime.Now.ToString() +"</otime><content>"+xmlfile+"</content><img>"+imgname+"</img></document>");
    doc.Save  (Server.MapPath("文件名"));
      

  2.   

    采用.NET所提供的XmlTextWriter类,如楼上所说的办法;你也可以采用SCHEMA的所带的一些方法!
      

  3.   

    我在本机上试了试,我用c#做的,可以实现,在web项目上新建一页,然后在page_load事件下写下面的代码,但是还要注意一点,就是你要先把你的应用程序所在的目录添加asp_net用户,使它有权限写,我是从数据库中读出数据到dataset中,再写入到test3.xml文件中:
    using System.Web;
    using System.Web.SessionState;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.HtmlControls;
    using System.Data.SqlClient;
    using System.IO;
    using System.Xml;
    using System.Text;
    private void Page_Load(object sender, System.EventArgs e)
    { SqlConnection sc=new SqlConnection("server=localhost;database=northwind;user id=sa;password=");
    sc.Open();
    SqlCommand scd=new SqlCommand("SELECT ProductID, ProductName FROM Products WHERE CategoryID = 1 ORDER BY ProductID",sc);
    SqlDataAdapter sda=new SqlDataAdapter(scd);
    DataSet ds=new DataSet();
    sda.Fill(ds,"product");
    sc.Close(); XmlTextWriter writer;
    String filepath = Server.MapPath("test3.xml");
                               //下面这一句就是你要的了
    writer = new XmlTextWriter(filepath,Encoding.UTF8); writer.WriteStartDocument();
    ds.WriteXml(writer);
    writer.Close();
    Page.Response.Redirect("test3.xml");

    }