你可以先用Stream按照指定的编码格式建立XML文件,然后用DataSet.Write(Stream,XmlWriteMode.WriteSchema)写入Stream就可以了

解决方案 »

  1.   

    TO qimini(循序渐进):
       你的方法不行啊,代码如下,请更正,谢谢!!
    XmlTextWriter xtw = new XmlTextWriter("D\slsl.xml",System.Text.Encoding.GetEncoding("gb2312"));
          ds.WriteXml( xtw ,XmlWriteMode.WriteSchema );
          xtw.Flush();
          xtw.Close();
    ds为已经被填充了数据的DATASET对象
      

  2.   


    string filename = "c:\\myXmlDoc.xml";
        // Create the FileStream to write with.
        System.IO.FileStream myFileStream = new System.IO.FileStream(filename, System.IO.FileMode.Create);
        // Create an XmlTextWriter with the fileStream.
        System.Xml.XmlTextWriter myXmlWriter = 
           new System.Xml.XmlTextWriter(myFileStream, System.Text.Encoding.GetEncoding("gb2312"));
        // Write to the file with the WriteXml method.
        ds.WriteXml(myXmlWriter);   
        myXmlWriter.Close();
      

  3.   

    To webdiyer(陕北吴旗娃):
        大侠你好,你的方法我试过了,还是没有能将gb2312写入到文件中。谢谢你的发言!
        我是用下面的方法实现的:
    XmlTextWriter xtw = new XmlTextWriter(this.XMLPath,System.Text.Encoding.GetEncoding("gb2312"));
    xtw.WriteRaw("<?xml version=\"1.0\" encoding=\"gb2312\"?>");
    this.ResumeInfoList.WriteXml( xtw ,XmlWriteMode.WriteSchema );
    xtw.Flush();
    xtw.Close();谢谢大家!!