Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / XML / July 2006

Tip: Looking for answers? Try searching our database.

XML serialization via XmlWriter creates 3 weird bytes

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Thomas S - 30 Jul 2006 00:51 GMT
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
Thomas S - 30 Jul 2006 06:01 GMT
It had something to do with the MemoryStream, not sure what.  It's working
now by writing from the XmlWriter directly to the StreamWriter.

>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
[quoted text clipped - 25 lines]
>
> T

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.