16Jul/092
XmlWriter and UTF-8 encoding without signature
I used this code to serialize some objects in Xml :
XmlWriter writer = new XmlTextWriter(stream, Encoding.UTF8);
But the output contains an UTF header, the Byte Order Mark (BOM). The use of the header/signature is usually for xml file, if you want to use the ouput in an HttpResponse, you don't need the signature. (some parser can cause a parsing error in java, like org.xml.sax.SAXException).
Here is the change to remove the BOM :
XmlWriter writer = new XmlTextWriter(stream, new UTF8Encoding(false));
January 28th, 2010 - 02:26
Thanks man, I read numerous other pages with all sorts of explanations on what to do but no example, yours was much easier and quicker
September 21st, 2011 - 10:33
Awesome! Just what I was after. Concise and to the point explanation of how to do it. Thanks.