Solved

Omitting Byte Order Mark

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to get the web content with different encodings 2 45
Run time Error 4 47
What is "public object" in C#? 3 45
Add different cell to otherwise similiar row 4 39
Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

776 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