The problem is that the underlying stream (in this case the xmlDoc
object) is using UTF-8, which is the default encoding in .NET.
From the MSDN documentation of the Encoding property of XmlWriterSettings:
The Encoding property only applies to the XmlWriter instances that are created either with the specified Stream or with the specified file name. If the XmlWriter instance is created with the specified TextWriter, the Encoding property is overridden by the encoding of the underlying TextWriter. For example, if this property is set to Unicode (UTF-16) for a particular XmlWriter, but the underlying writer is an StreamWriter (which derives from TextWriter) with its encoding set to UTF-8, the output will be UTF-8 encoded.
In order to resolve this, you need to create your XmlWriter
with a stream that is Latin-1 encoded. I don't think you can use a XmlDocument
for that.