4

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.

  • Does this happen if you start Emacs with emacs -q? If not, post your init file (~/.emacs or ~/.emacs.d/init.el). If it does, what about emacs -Q? – Gilles 'SO- stop being evil' Mar 9 '15 at 22:59
  • @Gilles Chinese characters also appear with -q and -Q as well. – Marcus Junius Brutus Mar 9 '15 at 23:17
0

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

| improve this answer | |
0

With this tag, emacs will save the xml file as utf-16 big endian with bom.

<?xml encoding="UTF-16"?>

Ascii tag (from IANA character sets):

<?xml encoding="US-ASCII">
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.