反序列化失败,xml中有特殊字符,这种情况怎么处理
1个回答
推荐于2018-04-21
展开全部
------Solutions------
DataTable table = new DataTable();
table.Columns.Add(new DataColumn("Test", typeof(string)));
DataRow row = table.NewRow();
row[0]="μ";
table.Rows.Add(row);
table.TableName = "test";
table.WriteXml("datatable.xml");
//读取
table.ReadXml("datatable.xml");
------Solutions------
序列化时指定编码
XmlSerializer xs = new XmlSerializer(typeof(TestClass));
FileStream fs = new FileStream(@"d:\test.xml", FileMode.Create);
xs1.Serialize(new XmlTextWriter(fs, Encoding.UTF8), obj);
fs.Close();
------Solutions------
有时候有/<>等字符也会失败,
办法就是转换为16进制保存
DataTable table = new DataTable();
table.Columns.Add(new DataColumn("Test", typeof(string)));
DataRow row = table.NewRow();
row[0]="μ";
table.Rows.Add(row);
table.TableName = "test";
table.WriteXml("datatable.xml");
//读取
table.ReadXml("datatable.xml");
------Solutions------
序列化时指定编码
XmlSerializer xs = new XmlSerializer(typeof(TestClass));
FileStream fs = new FileStream(@"d:\test.xml", FileMode.Create);
xs1.Serialize(new XmlTextWriter(fs, Encoding.UTF8), obj);
fs.Close();
------Solutions------
有时候有/<>等字符也会失败,
办法就是转换为16进制保存
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询