UTF-16 encoding

Jun 5, 2012 at 1:35 AM

...is because you serialise your XML to a StringBuilder. All .Net strings are Unicode. If you serialize to a FileStream you'll get the encoding you ask for.

(I normally prefer to expose a 'ToXml' method that takes a TextWriter / XmlWriter as an argument, then the API doesn't force you to go via one big intermediate string, and gives you the flexibility to write out as UTF-8 etc... if you want to)