How to retreive the xml file encoding ?

Questions about XML that are not covered by the other forums should go here.
sebastienlavandier
Posts: 124
Joined: Tue May 29, 2012 5:42 pm

How to retreive the xml file encoding ?

Post by sebastienlavandier »

Hi,

I want to know if a getter exist in the Oxygen Author API for find the xml file encoding ?
Something like: authorAccess.getDocumentController().getDoctype();

Thanks for your help.

Sébastien
Radu
Posts: 9055
Joined: Fri Jul 09, 2004 5:18 pm

Re: How to retreive the xml file encoding ?

Post by Radu »

Hi Sébastien,

We do not have such an API. Could you elaborate on the use case? Maybe we could add such API in the future.

If you use our "editorComponentProvider.getWSEditorAccess().save()" API the document will be saved with the proper encoding detected when it was opened.
But indeed if you create a reader over the document and then construct a file output stream on it you would need to know the proper encoding for saving the document.

One workaround would be to create the reader over the document's content and look in it for the XML
declaration:

Code: Select all

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
If it contains an encoding, it can be used for save. But it's more complicated because the encoding specified in the XML declaration is a IANA encoding and it needs to be converted to a Java encoding to be used when creating an OutputStreamWriter over the file output stream. The code we use to detect the proper encoding on save is quite large.
If there is no XML declaration or if it does not contain an encoding you fall-back to UTF-8.

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
sebastienlavandier
Posts: 124
Joined: Tue May 29, 2012 5:42 pm

Re: How to retreive the xml file encoding ?

Post by sebastienlavandier »

Hi Radu,

Ok, it's my conclusion too.

Thanks for your help again.
Sébastien.
Radu
Posts: 9055
Joined: Fri Jul 09, 2004 5:18 pm

Re: How to retreive the xml file encoding ?

Post by Radu »

Hi Sébastien,

I will also add an issue on our list so that in the future besides the API WSEditor.createContentReader() we could also add some API like WSEditor.createContentInputStream().

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
Radu
Posts: 9055
Joined: Fri Jul 09, 2004 5:18 pm

Re: How to retreive the xml file encoding ?

Post by Radu »

Hi Sébastien,

Oxygen 15.2 and the corresponding Author Component Project were released about a week ago.
In it we added the API:

ro.sync.exml.workspace.api.editor.WSEditorBase.createContentInputStream()

which should create an input stream with the proper encoding over the edited XML contents.

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
Post Reply