How to retreive the xml file encoding ?

Questions about XML that are not covered by the other forums should go here.
sebastienlavandier
Posts: 124

How to retreive the xml file encoding ?

Wed Sep 04, 2013 10:17 am

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: 5378

Re: How to retreive the xml file encoding ?

Wed Sep 04, 2013 11:19 am

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

Re: How to retreive the xml file encoding ?

Wed Sep 04, 2013 11:44 am

Hi Radu,

Ok, it's my conclusion too.

Thanks for your help again.
Sébastien.
Radu
Posts: 5378

Re: How to retreive the xml file encoding ?

Wed Sep 04, 2013 11:54 am

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: 5378

Re: How to retreive the xml file encoding ?

Mon Jan 27, 2014 2:00 pm

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

Return to “General XML Questions”

Who is online

Users browsing this forum: No registered users and 1 guest