Page 1 of 1

Grab XML with Unicode to DataGrid

Posted: Thu Jan 14, 2021 7:14 pm
by gilar
Does anyone know how to grab XML data with Unicode text into DataGrid?

XML file: https://drive.google.com/file/d/1aHlLyP ... sp=sharing
XML Preview

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<vMix_CGRundown>
	<Credit_Title>
		<Background ID="1" Wait="0" Status="false" Label="Background OFF">
		</Background>
		<TextCrew IDStart="1" IDEnd="1" Duration="3.4" Transition="500" Status="false" Label="Crew OFF">
		</TextCrew>
		<Commercials IDStart="1" IDEnd="1" Duration="3" Transition="500" Status="false" Label="Commercials OFF">
		</Commercials>
	</Credit_Title>
	<Shortcut>
		<Key> </Key>
	</Shortcut>
	<TAKE Row_1="">
		<INPUTNAME>NAMA.gtzip</INPUTNAME>
		<STATUS>Running</STATUS>
		<INPUT>2</INPUT>
		<OVERLAY>4</OVERLAY>
		<NAME></NAME>
		<CONTENT>رذدقكممهوي دخحجج |* حخدذ كقنٱ آسش رز ججع ظلم انفسكم</CONTENT>
		<VARIABLE>NAMA.Text |* KETERANGAN.Text</VARIABLE>
		<SELECTED>2</SELECTED>
		<img_CONTENT></img_CONTENT>
		<img_VARIABLE></img_VARIABLE>
		<img_SELECTED></img_SELECTED>
	</TAKE>
	<TAKE Row_2="">
		<INPUTNAME>NAMA.gtzip</INPUTNAME>
		<STATUS></STATUS>
		<INPUT>2</INPUT>
		<OVERLAY>4</OVERLAY>
		<NAME></NAME>
		<CONTENT>ハヤヌツテセスシ |* マヤハナネテ フレヱ ヰギ ガワ</CONTENT>
		<VARIABLE>NAMA.Text |* KETERANGAN.Text</VARIABLE>
		<SELECTED></SELECTED>
		<img_CONTENT></img_CONTENT>
		<img_VARIABLE></img_VARIABLE>
		<img_SELECTED></img_SELECTED>
	</TAKE>
	<TAKE Row_3="">
		<INPUTNAME>NAMA.gtzip</INPUTNAME>
		<STATUS></STATUS>
		<INPUT>2</INPUT>
		<OVERLAY>4</OVERLAY>
		<NAME></NAME>
		<CONTENT>ङघढ णन धध ॠ ॡॡऌॢ ३॥ |* ΔΕέ ζ ηκ Ή Θ</CONTENT>
		<VARIABLE>NAMA.Text |* KETERANGAN.Text</VARIABLE>
		<SELECTED>2</SELECTED>
		<img_CONTENT></img_CONTENT>
		<img_VARIABLE></img_VARIABLE>
		<img_SELECTED></img_SELECTED>
	</TAKE>
</vMix_CGRundown>
This is my code

Code: Select all

on vMix_LoadXML
   answer file "Select Draco Match Data" with filter "xml file, *.xml"
   if the result is not "cancel" then
      put it into tXMLPath
      vMix_createTree tXMLPath
      vMix_LoadRundown
   else
   end if
end vMix_LoadXML

on vMix_createTree tXMLPath
   --   put url ("binfile:"&tXMLPath)into tXMLData
   --   put revCreateXMLTree(tXMLData, false, true, false) into sXMLID
   
   --   put url ("binfile:/path/to/file/myUniText.ut8") into tRawTxt
   --   set the unicodetext of fld "display" to uniencode(tRawTxt,"UTF8")
   
   put url ("binfile:"&tXMLPath)into tXMLData
   put revCreateXMLTree(tXMLData, false, true, false) into sXMLID
end vMix_createTree

on vMix_LoadRundown
   put revXMLNumberOfChildren(sXMLID, "vMix_CGRundown", "TAKE", 2) into tNumberRow
   --   --- dgData (ambil data berdasarkan index)
   repeat with i=1 to tNumberRow
      put i into tRunDown[i]["ID"]
      put revXMLNodeContents(sXMLID, "/vMix_CGRundown/TAKE["&i&"]/INPUTNAME") into tRunDown[i]["INPUTNAME"]
      put revXMLNodeContents(sXMLID, "/vMix_CGRundown/TAKE["&i&"]/STATUS") into tRunDown[i]["STATUS"]
      put revXMLNodeContents(sXMLID, "/vMix_CGRundown/TAKE["&i&"]/INPUT") into tRunDown[i]["INPUT"]
      put revXMLNodeContents(sXMLID, "/vMix_CGRundown/TAKE["&i&"]/OVERLAY") into tRunDown[i]["OVERLAY"]
      put revXMLNodeContents(sXMLID, "/vMix_CGRundown/TAKE["&i&"]/NAME") into tRunDown[i]["NAME"]
      put revXMLNodeContents(sXMLID, "/vMix_CGRundown/TAKE["&i&"]/CONTENT") into tRunDown[i]["CONTENT"]
      put revXMLNodeContents(sXMLID, "/vMix_CGRundown/TAKE["&i&"]/VARIABLE") into tRunDown[i]["VARIABLE"]
      put revXMLNodeContents(sXMLID, "/vMix_CGRundown/TAKE["&i&"]/SELECTED") into tRunDown[i]["SELECTED"]
      put revXMLNodeContents(sXMLID, "/vMix_CGRundown/TAKE["&i&"]/img_CONTENT") into tRunDown[i]["img_CONTENT"]
      put revXMLNodeContents(sXMLID, "/vMix_CGRundown/TAKE["&i&"]/img_VARIABLE") into tRunDown[i]["img_VARIABLE"]
      put revXMLNodeContents(sXMLID, "/vMix_CGRundown/TAKE["&i&"]/img_SELECTED") into tRunDown[i]["img_SELECTED"]
   end repeat
   set the dgData of group "sequence_grd" of card "games_crd" to tRunDown
   --- Credit Title
   --- Checklist & Title
   set the label of button "Background_chkbx" of card "games_crd" to revXMLAttribute(sXMLID, "/vMix_CGRundown/Credit_Title/Background", "Label")
   set the label of button "Crew_chkbx" of card "games_crd" to revXMLAttribute(sXMLID, "/vMix_CGRundown/Credit_Title/TextCrew", "Label")
   set the label of button "Commercials_chkbx" of card "games_crd" to revXMLAttribute(sXMLID, "/vMix_CGRundown/Credit_Title/Commercials", "Label")
   ---
   set the hilite of button "Background_chkbx" of card "games_crd" to revXMLAttribute(sXMLID, "/vMix_CGRundown/Credit_Title/Background", "Status")
   set the hilite of button "Crew_chkbx" of card "games_crd" to revXMLAttribute(sXMLID, "/vMix_CGRundown/Credit_Title/TextCrew", "Status")
   set the hilite of button "Commercials_chkbx" of card "games_crd" to revXMLAttribute(sXMLID, "/vMix_CGRundown/Credit_Title/Commercials", "Status")
   --- Background
   put revXMLAttribute(sXMLID, "/vMix_CGRundown/Credit_Title/Background", "ID") into field "BG.CT.Line_fld" of card "games_crd"
   put revXMLAttribute(sXMLID, "/vMix_CGRundown/Credit_Title/Background", "ID") into field "BG.CT.Index_fld" of card "games_crd"
   put revXMLAttribute(sXMLID, "/vMix_CGRundown/Credit_Title/Background", "Wait") into field "BG.CT.Wait_fld" of card "games_crd"
   --- Text Crew
   put revXMLAttribute(sXMLID, "/vMix_CGRundown/Credit_Title/TextCrew", "IDStart") into field "CT_line.start_fld" of card "games_crd"
   put revXMLAttribute(sXMLID, "/vMix_CGRundown/Credit_Title/TextCrew", "IDStart") into field "CT_index.start_fld" of card "games_crd"
   put revXMLAttribute(sXMLID, "/vMix_CGRundown/Credit_Title/TextCrew", "IDEnd") into field "CT_line.End_fld" of card "games_crd"
   put revXMLAttribute(sXMLID, "/vMix_CGRundown/Credit_Title/TextCrew", "IDEnd") into field "CT_index.End_fld" of card "games_crd"
   put revXMLAttribute(sXMLID, "/vMix_CGRundown/Credit_Title/TextCrew", "Duration") into field "CT_duration.text_fld" of card "games_crd"
   put revXMLAttribute(sXMLID, "/vMix_CGRundown/Credit_Title/TextCrew", "Transition") into field "CT_duration.overlay_fld" of card "games_crd"
   --- Commercials
   put revXMLAttribute(sXMLID, "/vMix_CGRundown/Credit_Title/Commercials", "IDStart") into field "CT_commercials.line.start_fld" of card "games_crd"
   put revXMLAttribute(sXMLID, "/vMix_CGRundown/Credit_Title/Commercials", "IDStart") into field "CT_commercials.index.start_fld" of card "games_crd"
   put revXMLAttribute(sXMLID, "/vMix_CGRundown/Credit_Title/Commercials", "IDEnd") into field "CT_commercials.line.End_fld" of card "games_crd"
   put revXMLAttribute(sXMLID, "/vMix_CGRundown/Credit_Title/Commercials", "IDEnd") into field "CT_commercials.index.End_fld" of card "games_crd"
   put revXMLAttribute(sXMLID, "/vMix_CGRundown/Credit_Title/Commercials", "Duration") into field "CT_duration.commercials_fld" of card "games_crd"
   put revXMLAttribute(sXMLID, "/vMix_CGRundown/Credit_Title/Commercials", "Transition") into field "CT_duration.commercials.overlay_fld" of card "games_crd"
   --- Shortcut
   put revXMLNumberOfChildren(sXMLID, "vMix_CGRundown/Shortcut", "Key", 2) into tNumberRow
   repeat with i = 1 to tNumberRow
      put revXMLNodeContents(sXMLID, "/vMix_CGRundown/Shortcut/Key["&i&"]")&CR after tShortcutList
      delete line tNumberRow+1 of tShortcutList
   end repeat
   set the text of btn "shorccut_chc" of card "games_crd" to tShortcutList 
end vMix_LoadRundown
Comment and help would be appreciate

Re: Grab XML with Unicode to DataGrid

Posted: Fri Jan 15, 2021 5:29 pm
by gilar
Hi for every body has a same problem with me ...
I solve my problem with this

Code: Select all

 --   put textDecode(sXMLIDSatu,"UTF8") into sXMLID --- deccode Unicode Basic
      put textDecode (revXMLNodeContents(sXMLID, "/vMix_CGRundown/TAKE["&i&"]/INPUTNAME"),"UTF8") into tRunDown[i]["INPUTNAME"]
      put textDecode (revXMLNodeContents(sXMLID, "/vMix_CGRundown/TAKE["&i&"]/STATUS"),"UTF8") into tRunDown[i]["STATUS"]
      put textDecode (revXMLNodeContents(sXMLID, "/vMix_CGRundown/TAKE["&i&"]/INPUT"),"UTF8") into tRunDown[i]["INPUT"]
      put textDecode (revXMLNodeContents(sXMLID, "/vMix_CGRundown/TAKE["&i&"]/OVERLAY"),"UTF8") into tRunDown[i]["OVERLAY"]
      put textDecode (revXMLNodeContents(sXMLID, "/vMix_CGRundown/TAKE["&i&"]/NAME"),"UTF8") into tRunDown[i]["NAME"]
      put textDecode (revXMLNodeContents(sXMLID, "/vMix_CGRundown/TAKE["&i&"]/CONTENT"),"UTF8") into tRunDown[i]["CONTENT"]
      put textDecode (revXMLNodeContents(sXMLID, "/vMix_CGRundown/TAKE["&i&"]/VARIABLE"),"UTF8") into tRunDown[i]["VARIABLE"]
      put textDecode (revXMLNodeContents(sXMLID, "/vMix_CGRundown/TAKE["&i&"]/SELECTED"),"UTF8") into tRunDown[i]["SELECTED"]
      put textDecode (revXMLNodeContents(sXMLID, "/vMix_CGRundown/TAKE["&i&"]/img_CONTENT"),"UTF8") into tRunDown[i]["img_CONTENT"]
      put textDecode (revXMLNodeContents(sXMLID, "/vMix_CGRundown/TAKE["&i&"]/img_VARIABLE"),"UTF8") into tRunDown[i]["img_VARIABLE"]
      put textDecode (revXMLNodeContents(sXMLID, "/vMix_CGRundown/TAKE["&i&"]/img_SELECTED"),"UTF8") into tRunDown[i]["img_SELECTED"]

Re: Grab XML with Unicode to DataGrid

Posted: Fri Jan 15, 2021 6:43 pm
by FourthWorld
You could probably do the textDecode once on the full XML data before parsing.

Re: Grab XML with Unicode to DataGrid

Posted: Sat Jan 16, 2021 7:56 am
by raugert
I also ran into this a few weeks ago. http://forums.livecode.com/viewtopic.ph ... ic#p199600

I tried using textDecode on the full XML before parsing, but it didn't work to decode cyrillic characters. I ended up doing what gilar did ! It looks like the vMix XML is already textDecoded, but we have to textEncode it before we create the "revCreateXMLTree" and then textDecode it at the NodeContent or attribute level. Maybe the "revCreateXMLTree" is created in binary ? (Just a thought :? )

cheers,
Richard