Emacs automatically adding BOM to XML file

emacsunicode

This appears to be related to this discussion but I have exactly the opposite use case. I do not wish to insert a BOM but emacs appears to be inserting one in XML mode (without even being in hexl-mode). I am using GNU Emacs 23.3.1.

I have the following XML file:

$ cat a.xml 
<?xml encoding="UTF-16"?><a/>
$ xxd a.xml 
0000000: 3c3f 786d 6c20 656e 636f 6469 6e67 3d22  <?xml encoding="
0000010: 5554 462d 3136 223f 3e3c 612f 3e0a       UTF-16"?><a/>.

The file does not contain a BOM as can be seen.
When I try to open it with emacs a.xml this is what I see:
enter image description here

When I then switch to hexl-mode it appears that a BOM has been inserted:
enter image description here

This happens even if I start Emacs with emacs -Q.

Best Answer

The solution is to load the file with find-file-literally.

Related Question