VB.Net 2005: extra characters at beginning of xml file

k3n51mm

Active member
Joined
Mar 7, 2007
Messages
40
Programming Experience
3-5
The three following characters



are placed at the beginning of an xml file I am writing to disk by calling the xmlDoc.Save() method from VB.Net 2005. Example:

<?xml version="1.0" encoding="UTF-8"?>
<RootNode>
</RootNode>

This only occurred after I added the XML declaration node to the document.

I didn't tell Visual Studio to do this, therefore it's a bug. How can I stop it? I seem to remember these characters from somewhere else in the Microsoft world, but I can't recall what the problem was then either.
 
They are "byte-order marks" that tell editors what encoding is used, the one you posted is utf-8. How did you manage to get those bytes as printable, or to rephraze, how did you find an editor that doesn't recognize utf-8? In most cases these bytes should be there, and does not display when viewed/used with compliant readers.
 
UltraEdit

John, I was looking at the file in UltraEdit. When I opened it in Notepad, those characters did not show up. Really though, I was hoping I could get rid of them. So is this Visual Studio's way of saying 'this is a UTF-8 document'? And, is this a standard prefix for UTF-8? I remember seeing these characters before in other web-based document generation code I've written on the MS platform, and I always wanted to get rid of them.
 
Yes, it is the industry standard to enable reader to auto-detect encoding. No, you normally don't want to rid them.
 
Back
Top