C# 使用dotnet核心创建XML时使用大写UTF-8编码
此.Net Framework解决方案不再适用于Dotnet Core。使用Dotent Core 3.1.101和.Net Framework 4.7.1进行测试 有没有比这更优雅的解决方案? 在第242行的XmlEncodedRawTextWriter中, 使用的实例与我在XmlWriterSettings中设置的不同。 我想问题出在第175行 dotnetcore是否有其他方法以大写形式编写XML声明UTF-8 这是Apple Plist文件的要求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
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);
}