Create unicode XML file

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
gilar
Posts: 96
Joined: Sat Sep 26, 2015 12:59 pm

Create unicode XML file

Post by gilar » Wed Feb 15, 2017 3:47 am

Hello Every Body ....
I have problem to create an XML file which contain unicode font
i create a script in card and button to generate an XML file

this is my CARD SCRIPT

Code: Select all

local _tags
local _xml
local _level
local _tabs

function q pText
   return quote & pText & quote
end q

on startXML
   //put "<?xml version=" & q("1.0") & "?>" & return into _xml
   put "<?xml version=" & q("1.0") & " encoding=" & q("UTF-8") & "?>" & return into _xml
   /*
   versionnya pengen diupgrade ke 1.1 pake code ini
   ?xml version="1.1" encoding="UTF-8"?
   */
   put 0 into _level
   put empty into _tabs
   put empty into _tags
end startXML

on startTag pTag
   put _tabs & "<" & pTag & ">" & return after _xml
   add 1 to _level
   put pTag into _tags[_level]
   put tab after _tabs  
end startTag

on closeTag
   delete char 1 of _tabs
   put _tabs & "</" & _tags[_level] & ">" & return after _xml
   # Do a 'delete variable _tags[_level]' if you really want to clean the array as you go 
   subtract 1 from _level
end closeTag

on addAttribute pAttribute, pValue
   # This should go into the last tag, but as we have "proper XML" so far we can backtrace two chars (">" and newline)
   put space & pAttribute & "=" & q(pValue) before char -2 of _xml
end addAttribute

on writeContent pContent
   put _tabs & pContent & return after _xml
end writeContent

on writeNode pNode, pValue
   put _tabs & "<" & pNode & ">" & pValue & "</" & pNode & ">" & return after _xml
end writeNode

getProp xml
   return _xml
end xml

I have a button to generate XML ---> "GENERATE XML"
this is the script

Code: Select all

on mouseUp
   startXML
   startTag "DracoFootballXpression"
   startTag "General"
   //NAMA TIM
   startTag "TeamName"
   writeNode "HomeNameSmall", field "namatima_skt_fld" of card 002
   writeNode "HomeNameBig", field "namatima_fld" of card 002
   writeNode "AwayNameSmall", field "namatimb_skt_fld" of card 002
   writeNode "AwayNameBig", field "namatimb_fld" of card 002
.
.
.
.
.
closeTag // Draco Football Xpression
put the xml of this card into URL "file:C:/DracoXpression/DracoData.xml"
then i put "ĐUKANOVIĆ" into field "namatima_fld"
and push GENERATE button
here the result of XLM file

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<DracoFootballXpression>
	<General>
		<TeamName>
			<HomeNameSmall></HomeNameSmall>
			<HomeNameBig>?UKANOVI?</HomeNameBig>
			<AwayNameSmall></AwayNameSmall>
			<AwayNameBig></AwayNameBig>
		</TeamName>
.
.
.
.

when i check it with notepad this is not a unicode XML. this is ANSI
what I want is to be like this

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<DracoFootballXpression>
	<General>
		<TeamName>
			<HomeNameSmall></HomeNameSmall>
			<HomeNameBig>"ĐUKANOVIĆ"</HomeNameBig>
			<AwayNameSmall></AwayNameSmall>
			<AwayNameBig></AwayNameBig>
		</TeamName>
.
.
.
.
The question is
How to create an unicode XML file?

comment and help wouldbe appreciate


Thanks



Gilar Kadarsah
Newbie Programmer from Indonesia
Gilar | from INDONESIA

gilar
Posts: 96
Joined: Sat Sep 26, 2015 12:59 pm

Re: Create unicode XML file

Post by gilar » Wed Feb 15, 2017 6:03 am

I read this
http://stackoverflow.com/questions/1639 ... n-xml-file

and I put this code on the end my GENERATE script
uniDecode(uniEncode(myXMLData,"UTF8"))
then the script will be like this

Code: Select all

 put the xml of this card into it
 put uniDecode (uniEncode (it,"UTF8")) into url "binfile:C:/DracoXpression/sample.xml"
Here the XML file what i got

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<DracoFootballXpression>
	<HomeNameSmall></HomeNameSmall>
	<HomeNameBig>?UKANOVI?</HomeNameBig>
	<AwayNameSmall></AwayNameSmall>
	<AwayNameBig></AwayNameBig>
</DracoFootballXpression>
the I modified on my GENERATE script
.
.
.
.

put the xml of this card into it
put uniDecode (it,"UTF8") into url "binfile:C:/DracoXpression/sample.xml"
then the XML file will be like this

Code: Select all

㼼浸敶獲潩㵮ㄢ〮•湥潣楤杮∽呕ⵆ∸㸿㰊牄捡䙯潯扴污塬牰獥楳湯ਾ㰉潈敭慎敭浓污㹬⼼潈敭慎敭浓污㹬ऊ䠼浯乥浡䉥杩㼾䭕乁噏㽉⼼潈敭慎敭楂㹧ऊ䄼慷乹浡卥慭汬㰾䄯慷乹浡卥慭汬ਾ㰉睁祡慎敭楂㹧⼼睁祡慎敭楂㹧㰊䐯慲潣潆瑯慢汬灘敲獳潩㹮

Any suggest?
Gilar | from INDONESIA

Klaus
Posts: 13806
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Create unicode XML file

Post by Klaus » Wed Feb 15, 2017 1:58 pm

Dobar dan gilar,

"uniencode" and "unidecode" have been deprecated since version 7 of Livecode!
What version are you using? If version >=7 use "textencode"/"textdecode"!

So something like this as the final step should work:
...
put the xml of this card into tXMLFinal
put textencode(tXMLFinal,"UTF8") into url "binfile:C:/DracoXpression/sample.xml"
...


Best

Klaus

gilar
Posts: 96
Joined: Sat Sep 26, 2015 12:59 pm

Re: Create unicode XML file

Post by gilar » Wed Feb 15, 2017 7:47 pm

Klaus wrote:Dobar dan gilar,

"uniencode" and "unidecode" have been deprecated since version 7 of Livecode!
What version are you using? If version >=7 use "textencode"/"textdecode"!
I use Livecode version 8, for some reason
now back to use version 7
Klaus wrote: So something like this as the final step should work:
...
put the xml of this card into tXMLFinal
put textencode(tXMLFinal,"UTF8") into url "binfile:C:/DracoXpression/sample.xml"
...

Best

Klaus
This script works like a charm, very good and simple

Thank you very much Klaus



Best Regards

Gilar | Indonesia
Gilar | from INDONESIA

MaxV
Posts: 1579
Joined: Tue May 28, 2013 2:20 pm
Location: Italy
Contact:

Re: Create unicode XML file

Post by MaxV » Tue Mar 14, 2017 2:14 pm

Also urlencode and uldecode can save a lot of problems. All is converted to standard ASCII.

Fore example: put urlencode("ĐUKANOVIĆ") = "%3FUKANOVI%3F"
Livecode Wiki: http://livecode.wikia.com
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w

Post Reply

Return to “Getting Started with LiveCode - Experienced Developers”