Page 1 of 1

Import utf8 XML to datagrid edit and save to utf8 xml

Posted: Thu Dec 05, 2013 9:31 am
by Nicke
Hi,

I'm trying to import a xmlfile encoded in utf8 (checked by Notepad++) to a datagrid. Editing of the text can/will happen and then I want to save the datagrid back to a utf8 encoded xmlfile.

By using this line I got the characters to show up right in the datagrid:

Code: Select all

put uniDecode(uniEncode(tTitle, "UTF8")) into theDataA[i]["title"]
but I have never managed to get the output to be anything other than ANSI according to Notepad++, and if I try to open the saved file LC tells me "Input is not proper UTF-8, indicate encoding!". The code below is now stripped from all utf8 conversion since none of them worked. I have read the utf8 tutorial (/s/lessons/m/4067/l/20441-unicode) but I do not get it. So my question is, how do I get the datagrid to become utf8 and how do I get the data out to a utf8 encoded xml file?

Code: Select all

command uiExportData outputFile
   ## Export data to XML
   ## Get Data Grid Array
   put the dgData of group "mainGrid" into theDataA
   
   ## Get indexes in proper order
   put the dgIndexes of group "mainGrid" into theIndexes
   
   ## Prefix XML
   put "<?xml version='1.0' encoding='utf-8'?>" & cr into theXML
   put"<!DOCTYPE RUNDOWN>" & cr after theXML
   put"<RUNDOWN VERSION='1.0'>" & cr after theXML
   
   ## Loop through data, putting into XML format
   repeat for each item theIndex in theIndexes
      put tab & "<ENTRY>" & cr after theXML
      put tab & tab & "<ORDER>" & theDataA[theIndex]["order"] & "</ORDER>" & cr after theXML
      put tab & tab & "<TITLE>" & theDataA[theIndex]["title"] & "</TITLE>" & cr after theXML
      put tab & tab & "<CHANNEL>" & theDataA[theIndex]["ch"] & "</CHANNEL>" & cr after theXML
      put tab & tab & "<LAYER>" & theDataA[theIndex]["lay"] & "</LAYER>" & cr after theXML
      put tab & tab & "<TYPE>" & theDataA[theIndex]["type"] & "</TYPE>" & cr after theXML
      put tab & "</ENTRY>" & cr after theXML
   end repeat
   
   ## Close root XML tag
   put "</RUNDOWN>" after theXML
   put outputFile into tFileName
   
   ## Ensure the file extension is xml
   set the itemDel to "."
   if item 2 of tFileName is not "xml" then
      put "xml" into item 2 of tFileName
   end if
   put theXML into tFileContents
   put tFileContents into URL ("file:" & tFileName)
end uiExportData

Re: Import utf8 XML to datagrid edit and save to utf8 xml

Posted: Fri Dec 06, 2013 3:19 am
by Simon
Hi Nicke,
Here is a start for when you save the file

Code: Select all

put unidecode(tFileContents,"utf8") into url ("binfile:"& tFileName)
But I have a feeling you may need more in here if it contains UTF8 text

Code: Select all

put tab & tab & "<ORDER>" & theDataA[theIndex]["order"] & "</ORDER>" & cr after theXML
Simon

Re: Import utf8 XML to datagrid edit and save to utf8 xml

Posted: Fri Dec 06, 2013 7:21 pm
by Nicke
Hi Simon,

I tried to save using the line you suggested:

Code: Select all

put unidecode(tFileContents,"utf8") into url ("binfile:"& tFileName)
But the outputted file is totally unreadable and according to Notepad++ still ANSI.

This is the content of tFileContents before the line above:

Code: Select all

<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE RUNDOWN>
<RUNDOWN VERSION='1.0'>
	<ENTRY>
		<ORDER>1</ORDER>
		<TITLE>Detta är en 'konstig' "text"</TITLE>
		<CHANNEL>1</CHANNEL>
		<LAYER>1</LAYER>
		<TYPE>Media</TYPE>
	</ENTRY>
	<ENTRY>
		<ORDER>2</ORDER>
		<TITLE>"Funkar detta"</TITLE>
		<CHANNEL>1</CHANNEL>
		<LAYER>2</LAYER>
		<TYPE>CG</TYPE>
	</ENTRY>
</RUNDOWN>
and when I open the file in notepad++ it looks like this:

Code: Select all

㼼浸敶獲潩㵮ㄧ〮‧湥潣楤杮✽瑵ⵦ✸㸿㰊䐡䍏奔䕐删乕佄乗ਾ刼乕佄乗嘠剅䥓乏✽⸱✰ਾ㰉久剔㹙ऊ㰉剏䕄㹒㰱伯䑒剅ਾउ吼呉䕌䐾瑥慴⁲湥✠潫獮楴❧∠整瑸㰢启呉䕌ਾउ䌼䅈乎䱅ㄾ⼼䡃乁䕎㹌ऊ㰉䅌䕙㹒㰱䰯奁剅ਾउ吼偙㹅敍楤㱡启偙㹅ऊ⼼久剔㹙ऊ䔼呎奒ਾउ似䑒剅㈾⼼剏䕄㹒ऊ㰉䥔䱔㹅䘢湵慫⁲敤瑴≡⼼䥔䱔㹅ऊ㰉䡃乁䕎㹌㰱䌯䅈乎䱅ਾउ䰼奁剅㈾⼼䅌䕙㹒ऊ㰉奔䕐䌾㱇启偙㹅ऊ⼼久剔㹙㰊刯乕佄乗
Any ideas?

Re: Import utf8 XML to datagrid edit and save to utf8 xml

Posted: Fri Dec 06, 2013 7:43 pm
by Simon
Hi Nicke,
I got that info from here:
http://lessons.runrev.com/s/lessons/m/4 ... 41-unicode

Simon