Solved

Omitting Byte Order Mark

Posted on 2006-11-28
2
1,030 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 19

Accepted Solution

by:
Daniel Van Der Werken earned 500 total points
Comment Utility
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
Comment Utility
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Bit flags and bit flag manipulation is perhaps one of the most underrated strategies in programming, likely because most programmers developing in high-level languages rely too much on the high-level features, and forget about the low-level ones. Th…
Introduction                                                 Was the var keyword really only brought out to shorten your syntax? Or have the VB language guys got their way in C#? What type of variable is it? All will be revealed.   Also called…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

772 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

12 Experts available now in Live!

Get 1:1 Help Now