XML Writer-无法将UTF16覆盖为UTF8

时间:2019-03-13 07:39:07

标签: c#

我正在尝试使用XMLWriter构建XML,但是它包含编码UTF-16。我尝试了将其修改为UTF-8的解决方案。但是没有任何作用

      var settings = new XmlWriterSettings
            {
                Encoding = new UTF8Encoding(true),
                Indent = false,
                OmitXmlDeclaration = false,
                NewLineHandling = NewLineHandling.None
            };

1 个答案:

答案 0 :(得分:0)

尝试覆盖UTF8String Writer

   private class UTF8StringWriter : StringWriter
    {
        public override Encoding Encoding
        {
            get
            {
                return Encoding.UTF8;
            }
        }
    }