Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Diagram.saveToXml(filename) producing UCS-2 encoded file? (Read 3962 times)
Rennie
Full Member
***
Offline


I Love MindFusion!

Posts: 108
Location: Copenhagen, Denmark
Joined: Jul 17th, 2012
Diagram.saveToXml(filename) producing UCS-2 encoded file?
Oct 27th, 2013 at 3:07am
Print Post  
When I use Diagram.saveToXml(filename) on my Android device, and then copy the file to a Windows machine, and load it into Notepad++, it says the file is encoded in UCS-2. Wouldn't it be better to save the file in UTF-8? Or am I doing something wrong?
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Diagram.saveToXml(filename) producing UCS-2 encoded file?
Reply #1 - Oct 28th, 2013 at 12:20pm
Print Post  
In WinForms version the encoding is selected automatically by the MSXML API based on text content. I think we stick to UTF-16 in Java because our developers could not find a way to implement such auto-detection there. The encoding should be UTF-16 and not UCS-2 actually, we setup the following options in code for the stream writer and XML document:

transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-16");
...
new OutputStreamWriter(stream, "UTF-16")

UTF-16 and UCS-2 are the same except for high-order codes (larger than 65536) according to http://www.coderanch.com/t/278588//java/writing-UCS-encoded-files-Java, so perhaps it's detected as UCS-2 by notepad++ because there are no such symbols in the file.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Rennie
Full Member
***
Offline


I Love MindFusion!

Posts: 108
Location: Copenhagen, Denmark
Joined: Jul 17th, 2012
Re: Diagram.saveToXml(filename) producing UCS-2 encoded file?
Reply #2 - Oct 29th, 2013 at 3:00am
Print Post  
This doesn't really matter for me, as I don't plan on saving XML to a file on Android in my app, that was just for testing.

Still, I think it's more "standard" to write text-based files as UTF-8 than UTF-16.

Maybe add an overload for saveToXml() that takes an additional argument so caller can specify "UTF-8" or "UTF-16"?
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Diagram.saveToXml(filename) producing UCS-2 encoded file?
Reply #3 - Oct 29th, 2013 at 6:43am
Print Post  
I don't think one or the other is more standard, and both .NET and Java store strings in UTF-16 format internally, so you can avoid some encoding conversions if you store the XML files in Unicode 16 too. You could use the saveToXml(Document) method to get the XML DOM tree in a Document object, and then save it in UTF-8 format if you prefer.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint