Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Omitting Byte Order Mark

Posted on 2006-11-28
2
Medium Priority
?
1,040 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 1000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
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.
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Loops Section Overview
Suggested Courses

916 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