all groups > dotnet xml > july 2006 >
You're in the

dotnet xml

group:

XML serialization via XmlWriter creates 3 weird bytes


XML serialization via XmlWriter creates 3 weird bytes Thomas S
7/29/2006 4:51:52 PM
dotnet xml: I want to serialize an object via XmlWriter, but when I serialize to that, 3
strange bytes are added to the beginning of the output (0xEF, 0xBB, and
0xBF) all of which are in the ASCII range (ASCII 239, 187, 191)

public static void writeLogItem(LogItem ilog, string lfile)
{
lock (logLock)
{
using (StreamWriter outfile = new StreamWriter(lfile, true))
{
MemoryStream mstrm = new MemoryStream();
XmlSerializer writer = new
XmlSerializer(ilog.GetType());
XmlWriter xwrite = XmlWriter.Create(mstrm);
writer.Serialize(xwrite, ilog);
//writer.Serialize(mstrm, ilog);
outStatus("mstrm: " +
bytes2hex(mstrm.ToArray()).Substring(0,9) );
outfile.WriteLine(Encoding.UTF8.GetString(mstrm.ToArray()).Replace(Environment.NewLine,
string.Empty));
}
}
}

Any idea why?

T

Re: XML serialization via XmlWriter creates 3 weird bytes Thomas S
7/29/2006 10:01:55 PM
It had something to do with the MemoryStream, not sure what. It's working
now by writing from the XmlWriter directly to the StreamWriter.

[quoted text, click to view]

AddThis Social Bookmark Button