Import utf8 XML to datagrid edit and save to utf8 xml
Posted: Thu Dec 05, 2013 9:31 am
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:
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?
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"]
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