数据库环境redhat / aix
数据库 db28.1要求,是winform,只为读出表中数据生成xml 文件,并不为显示用。
但用vi txt 等工具打开时中文为乱码想要一通用的datable生成xml文件的方法,我使用的方法如下: public void CrtXml(DataTable dt)
{
//方法一
//XmlDocument doc = new XmlDocument();
//doc.LoadXml(dt.GetXml());
//dt.Clear();
//dt.Dispose();
//XmlDeclaration xd = doc.CreateXmlDeclaration("1.0", "GB2312", "yes");
//XmlElement xe = doc.DocumentElement;
//doc.InsertBefore(xd, xe);
//doc.Save(this._xmlFile);//方法二
//FileStream fs = new FileStream(this._xmlFile, FileMode.Create);
//XmlTextWriter xtw = new XmlTextWriter(fs, Encoding.Unicode);
//dt.WriteXml(xtw);
//xtw.Close(); //XmlTextWriter writer = new XmlTextWriter(this._xmlFile, Encoding.UTF8);//Encoding.GetEncoding("gb2312"));
//writer.Formatting = Formatting.Indented;
//writer.Indentation = 4;
//writer.IndentChar = ' ';
//writer.WriteStartDocument();
//dt.WriteXml(writer);
//writer.Flush();
//writer.Close();//方法三
dt.WriteXml(this._xmlFile);
}这三种方法都是用了WriteXml (也测试过DataSet.WriteXml 也不行)
数据库 db28.1要求,是winform,只为读出表中数据生成xml 文件,并不为显示用。
但用vi txt 等工具打开时中文为乱码想要一通用的datable生成xml文件的方法,我使用的方法如下: public void CrtXml(DataTable dt)
{
//方法一
//XmlDocument doc = new XmlDocument();
//doc.LoadXml(dt.GetXml());
//dt.Clear();
//dt.Dispose();
//XmlDeclaration xd = doc.CreateXmlDeclaration("1.0", "GB2312", "yes");
//XmlElement xe = doc.DocumentElement;
//doc.InsertBefore(xd, xe);
//doc.Save(this._xmlFile);//方法二
//FileStream fs = new FileStream(this._xmlFile, FileMode.Create);
//XmlTextWriter xtw = new XmlTextWriter(fs, Encoding.Unicode);
//dt.WriteXml(xtw);
//xtw.Close(); //XmlTextWriter writer = new XmlTextWriter(this._xmlFile, Encoding.UTF8);//Encoding.GetEncoding("gb2312"));
//writer.Formatting = Formatting.Indented;
//writer.Indentation = 4;
//writer.IndentChar = ' ';
//writer.WriteStartDocument();
//dt.WriteXml(writer);
//writer.Flush();
//writer.Close();//方法三
dt.WriteXml(this._xmlFile);
}这三种方法都是用了WriteXml (也测试过DataSet.WriteXml 也不行)
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货