Solved

Omitting Byte Order Mark

Posted on 2006-11-28
2
1,034 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

740 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