DataSet生成gb2312编码的xml
时间:2011-05-10 来源:uwking
DataSet ds = new DataSet("terminal");
DataTable dt = new DataTable("terminalDev");
dt.Columns.Add("devClass", typeof(string));
dt.Columns.Add("deviceId", typeof(string));
dt.Columns.Add("version", typeof(string));
DataRow row = dt.NewRow();
row["devClass"] = txtPlayerName.Text;
row["deviceId"] = txtPlayerNo.Text;
row["version"] = txtVersion.Text;
dt.Rows.Add(row);
ds.Tables.Add(dt);
string setPath = String.Format("{0}Terminal\\terminal.xml",GetCurrentPath()) ; //GetCurrentPath()是应用程序路径
if (ds != null)
{
FileStream fs = new FileStream(setPath, FileMode.Create);
XmlTextWriter xtr = new XmlTextWriter(fs, System.Text.Encoding.GetEncoding("gb2312"));
//加入了下面的指定就可以了
xtr.Formatting = Formatting.Indented;
xtr.Indentation = 6;
xtr.WriteStartDocument();
ds.WriteXml(xtr);
xtr.Close();
fs.Close();
}