oXygen changes file enconding when saving

Having trouble installing <oXygen/>? Got a bug to report? Post it all here.
xinelo
Posts: 33
Joined: Wed Oct 04, 2006 6:25 pm

oXygen changes file enconding when saving

Post by xinelo » Wed Jun 15, 2011 4:12 pm

Hi,

I am editing a file which is encoded in UCS-2 Little Endian. After editing it, it doesn't work anymore, and I noticed that it might be due to the fact that oXygen changes the encoding to UTF-8 without BOM when saving the file.

This is the default behaviour, because I haven't changed any settings yet. I find it very inconvenient.

I've got two questions:
- a) What is this configured this way?
- b) How can I change that behaviour so that the enconding of the file is not changed? I've checked the preferences but I'm not sure what option might do this.

I hope someone can give me some hint. Thanks a lot! :)
Cheers, Manuel

adrian
Posts: 2699
Joined: Tue May 17, 2005 4:01 pm

Re: oXygen changes file enconding when saving

Post by adrian » Wed Jun 15, 2011 5:40 pm

Hello,

If it's an XML file then Oxygen uses the encoding mentioned in the XML declaration from the XML file.
e.g.

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
The BOM is also considered, but you should make sure that the BOM and encoding from the XML declaration don't contradict each other.

Details on how Oxygen handles encodings when opening a file can be found here:
http://www.oxygenxml.com/doc/ug-oxygen/ ... ments.html


Note however, UCS-2 is not in the list of encodings supported by Oxygen. The best you can do is open it in Oxygen as UTF-16(which supersedes UCS-2) but I'm not sure if it will be decoded properly. Obviously you won't be able to save it back to UCS-2 since it's not supported. Again, the closest you can get is to use UTF-16.

Regards,
Adrian
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com

xinelo
Posts: 33
Joined: Wed Oct 04, 2006 6:25 pm

Re: oXygen changes file enconding when saving

Post by xinelo » Thu Jun 16, 2011 12:28 pm

Hi Adrian,

Thank you very much for your reply!

My XML file's declaration is simply:

Code: Select all

<?xml version="1.0"?>
I thought UCS-2 and UTF-16 were the same thing, but it seems they're not. Well, what you explains why the encoding is changed:
UCS-2 is not in the list of encodings supported by Oxygen. (...) you won't be able to save it back to UCS-2 since it's not supported.
I noticed that oXygen changed something because the file didn't work anymore after saving, and because its size was reduced to its half (from 8Mb to 4Mb).

The file command in cygwin only says the file is "XML document text" regardless of its encoding. I could see the encoding changed opening the file in Notepad++ before and after saving in with oXygen (I don't know whether oXygen has any similar function).

One the other hand, the documentation page you suggested says:
When the encoding type cannot be determined, Oxygen prompts and display the Available Java Encodings dialog which provides a list of all encodings supported by the Java platform.
but that doesn't happen in my case, the file is saved in my new encoding without prompting any dialog.

How can I instruct oXygen to use a particular code chart when loading the file or when saving it?

Deeply grateful for your help,
Manuel

sorin_ristache
Posts: 4144
Joined: Fri Mar 28, 2003 2:12 pm

Re: oXygen changes file enconding when saving

Post by sorin_ristache » Thu Jun 16, 2011 3:31 pm

xinelo wrote:One the other hand, the documentation page you suggested says:
When the encoding type cannot be determined, Oxygen prompts and display the Available Java Encodings dialog which provides a list of all encodings supported by the Java platform.
but that doesn't happen in my case, the file is saved in my new encoding without prompting any dialog.
Oxygen displays the dialog with all available encodings on the computer only on opening the document, when the encoding cannot be detected from the encoding declaration and/or BOM. Once the document is opened in an editor panel, the encoding of the file was already determined and will be applied when saving the document without displaying again the dialog with available encodings.
xinelo wrote:How can I instruct oXygen to use a particular code chart when loading the file or when saving it?
With the encoding declaration at the beginning of the file, that is by starting the file with

Code: Select all

<?xml version="1.0" encoding="UTF-16"?>
instead of

Code: Select all

<?xml version="1.0"?>

Regards,
Sorin

xinelo
Posts: 33
Joined: Wed Oct 04, 2006 6:25 pm

Re: oXygen changes file enconding when saving

Post by xinelo » Fri Jun 17, 2011 2:38 pm

In my case, the first time I open the file, oXygen prompts me to choose one from the list of available editors, so as to associate my user-defined extension with the file type. However, I don't have a choice about the encoding.

I'll check whether I can add the encoding to the declaration. It seems the files work after adding UTF-16. If I open the file and change the declaration to

Code: Select all

<?xml version="1.0" encoding="UTF-16"?>
and then save, it seems the encoding is not changed. So it looks fine.

Thanks a lot, Sorin and Adrian.
Manuel

Post Reply