How to use XmlWriter along with StringWriter to properly serialize a UTF-8 string
nicolaiarocci.substack.com
Today, I (re)learned how to serialize an XML to a UTF-8 string. Like all the other times I did this, I got backstabbed by StringWriter, which only supports UTF-16. A simple code snippet like this: await using var sw = new StringWriter(); await using var w = XmlWriter.Create(sw, new() { Async = true }); ... await w.FlushAsync(); return sw.ToString();
How to use XmlWriter along with StringWriter to properly serialize a UTF-8 string
How to use XmlWriter along with StringWriter…
How to use XmlWriter along with StringWriter to properly serialize a UTF-8 string
Today, I (re)learned how to serialize an XML to a UTF-8 string. Like all the other times I did this, I got backstabbed by StringWriter, which only supports UTF-16. A simple code snippet like this: await using var sw = new StringWriter(); await using var w = XmlWriter.Create(sw, new() { Async = true }); ... await w.FlushAsync(); return sw.ToString();