Home » Questions » Computers [ Ask a new question ]

Make emacs not remove the BOM from XML files

Make emacs not remove the BOM from XML files

I use Emacs to edit an XML file that is also read by another application. The other application requires that the file start with a byte-order marker (BOM). However, Emacs seems to remove the BOM every time I edit the file. Is there a way to make Emacs leave the BOM alone?

Asked by: Guest | Views: 391
Total answers/comments: 2
Guest [Entry]

"Emacs will write a BOM or not depending on what coding system it is using. Emacs automatically chooses the coding system it uses when visiting a file.

You can change the coding system to utf-8-with-signature, which will tell Emacs to write the BOM.

To change the coding system of a visited file:

C-x RET r utf-8-with-signature RET

You can set the coding system that Emacs uses for a particular file by setting a file variable. See the fine manual section 57.3.4 Local Variables in Files to learn how to do that."
Guest [Entry]

Emacs "itself" should not mess with the BOM; if it's really doing that, then it would have to be the code implementing the Emacs "mode" you are useing to edit your XML files which removes the BOM. Since you don't say which one that is, I can only refer you to the documentation for that mode, or that you open the files in fundamental-mode (or similar non-destructive mode). Or try M-x find-file-literally if all else fails.