Solved

Omitting Byte Order Mark

Posted on 2006-11-28
2
1,031 Views
Last Modified: 2008-01-09
I'm using .net 1.1 and am trying to write UTF-8 XML without a Byte Order Mark.  According to everything I have read, this shouldn't be hard, but unfortunately it isn't proving that easy for me.  Here's the code I'm working with

XmlDataDocument doc = new XmlDataDocument();
.....
XmlTextWriter fs = new XmlTextWriter(fileName, new System.Text.UTF8Encoding(false));
doc.Save(fs);
fs.Close();

This *kind of* works in the sense that the UTF-8 BOM is not included in the file, however the UTF-16 BOM (FF FE) is included in the file.

Replacing the XmlTextWriter declaration Encoding argument with "null" will remove all BOMs, however the text is then ASCII encoded and not UTF-8.  I'm really trying to figure out how to write UTF-8 WITHOUT a BOM.  Any help would be greatly appreciated.
0
Comment
Question by:CaptainBob007
2 Comments
 
LVL 20

Accepted Solution

by:
Daniel Van Der Werken earned 500 total points
ID: 18038865
Try using StreamWriter and creatiung a stream with the encoding.  Then, use the constructor for XmlTextWriter that only takes the TextWriter based StreamWriter argument.  See if that solves this.  Maybe it's a bug or limitation in XmlTextWriter and using StreamWriter will solve it?

0
 

Author Comment

by:CaptainBob007
ID: 18039637
That doesn't work either.  Here's what I tried:

StreamWriter sw = new StreamWriter(outputFile,false,new System.Text.UTF8Encoding(false));
XmlTextWriter fs = new XmlTextWriter(sw);
fs.Formatting = Formatting.Indented;
doc.Save(fs);
sw.Close();

And it still has the "FFFE" at the beginning on the output file
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now