我正在使用 Stringwriter 序列化我的对象DataCheck并将文本写入变量 strData。最后 strdata 的值进入数据库。
StringWriter writer = new StringWriter();
XmlSerializer serializer = new XmlSerializer(typeof(DataCheck));
serializer.Serialize(writer, objData);
string strData = writer.ToString();
如果我检查变量 strdata 的内容,它带有默认编码(encoding="utf-16")
字符串 strData 值低于
<?xml version="1.0" encoding="utf-16"?>
<DataCheck xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<JobList>
<Job>
<JobId>500</JobId>
<JobDate>1/1/2013</JobDate>
<Jobdesc>Test the app </Jobdesc>
</Job>
</JobList>
</DataCheck>
问。我需要删除此编码,以便我的 XML 内容看起来像没有编码如何执行此操作以及我缺少什么。
<?xml version="1.0"?>
<DataCheck xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<JobList>
<Job>
<JobId>500</JobId>
<JobDate>1/1/2013</JobDate>
<Jobdesc>Test the app </Jobdesc>
</Job>
</JobList>
</DataCheck>