Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/297.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用dotnet核心创建XML时使用大写UTF-8编码_C#_Xml_.net Core_Linq To Xml_Declaration - Fatal编程技术网

C# 使用dotnet核心创建XML时使用大写UTF-8编码

C# 使用dotnet核心创建XML时使用大写UTF-8编码,c#,xml,.net-core,linq-to-xml,declaration,C#,Xml,.net Core,Linq To Xml,Declaration,此.Net Framework解决方案不再适用于Dotnet Core。使用Dotent Core 3.1.101和.Net Framework 4.7.1进行测试 有没有比这更优雅的解决方案? 在第242行的XmlEncodedRawTextWriter中, 使用的实例与我在XmlWriterSettings中设置的不同。 我想问题出在第175行 dotnetcore是否有其他方法以大写形式编写XML声明UTF-8 这是Apple Plist文件的要求 var doc = new XDocu

此.Net Framework解决方案不再适用于Dotnet Core。使用Dotent Core 3.1.101和.Net Framework 4.7.1进行测试

有没有比这更优雅的解决方案?

在第242行的XmlEncodedRawTextWriter中, 使用的实例与我在XmlWriterSettings中设置的不同。 我想问题出在第175行

dotnetcore是否有其他方法以大写形式编写XML声明UTF-8

这是Apple Plist文件的要求

var doc = new XDocument(
    new XDocumentType("plist", "-//Apple//DTD PLIST 1.0//EN", "http://www.apple.com/DTDs/PropertyList-1.0.dtd", null),
    new XElement("plist"))
{
    Declaration = new XDeclaration("1.0", "UTF-8", string.Empty)
};


var settings = new XmlWriterSettings
{
    //Encoding = new UTF8Encoding()
    Encoding = new UpperCaseUTF8Encoding()
};

using (var xmlWriter = XmlWriter.Create("demo.xml", settings))
{
    Console.WriteLine($"{xmlWriter.Settings.Encoding.WebName}, {settings.Encoding.WebName}");
    doc.Save(xmlWriter);
}
public class UpperCaseUTF8Encoding : UTF8Encoding
{
    public UpperCaseUTF8Encoding() : this(false)
    {
    }

    public UpperCaseUTF8Encoding(bool encoderShouldEmitUTF8Identifier) : this(encoderShouldEmitUTF8Identifier, false)
    {
    }

    public UpperCaseUTF8Encoding(bool encoderShouldEmitUTF8Identifier, bool throwOnInvalidBytes) : base(encoderShouldEmitUTF8Identifier, throwOnInvalidBytes)
    {
    }

    public override string WebName => base.WebName.ToUpper(CultureInfo.InvariantCulture);
}