My goal is to get a binary buffer (MemoryStream.ToArray()
would yield byte[]
in this case) of XML without losing the Unicode characters. I would ex
You can use XmlWriter instead:
var doc = new XmlDocument();
doc.LoadXml("<x>“∞π”</x>");
using (var buf = new MemoryStream())
{
using (var writer = XmlWriter.Create(buf,
new XmlWriterSettings{Encoding= Encoding.ASCII}))
{
doc.Save(writer);
}
Console.Write(Encoding.ASCII.GetString(buf.ToArray()));
}
Outputs:
<?xml version="1.0" encoding="us-ascii"?><x>“∞π”</x>