Re: XML beginner question (about special characters display)
Re: XML beginner question (about special characters display)
- Subject: Re: XML beginner question (about special characters display)
- From: John Delacour <email@hidden>
- Date: Sat, 12 Oct 2002 22:52:22 +0100
- Mac-eudora-version: 5.3 alpha
At 2:36 pm +0200 11/10/02, JJ wrote:
I like perl solution.
Hmmmm.... What should I do? I'll try your three suggestions...
Here is a script that simplifies the whole process. Unfortunately
'do shell script...' breaks if it has to deal with hi ascii, which is
a serious bug, but this can be avoided if the whole process is
file-based. So this script takes a string, obtained however you
like, and converts it to the html entities.
set macstring to "some lo/hi ASCII Mac characters"
-- or get macstring by some other means
set htmlstring to convertString(macstring)
-- and do what you want with it
--
on convertString(s)
set {d, tmp} to {current date, path to temporary items as string}
set n to d - (get date (("1/1/" & (d's year) + 1)))
(* Create pathnames for perl script and text file *)
set fpl to tmp & "temp" & n & ".pl"
set ftxt to tmp & "temp" & n & ".txt"
set fplu to POSIX path of fpl
set fpluq to "'" & fplu & "'"
set ftxtu to POSIX path of ftxt
set ftxtuq to "'" & ftxtu & "'"
open for access file ftxt with write permission
set eof file ftxt to 0
write s to file ftxt
close access file ftxt
set perlscript to "#!/usr/bin/perl
## Read the text file and do the conversion ;
$macstring = <ARGV> ;
## Load the conversion table
table();
$ftxt = \"" & ftxtu & "\" ;
## Create and write to the text file
open FTXT, \">$ftxt\" or die $! ;
for ($macstring) {
s~([\\x80-\\xFF])~$macToUnicode{$1}~g;
print FTXT;
}
sub table {
%macToUnicode = (
\"\\x80\"=>'Ä',\"\\x81\"=>'Å',\"\\x82\"=>'Ç',
\"\\x83\"=>'É',\"\\x84\"=>'Ñ',\"\\x85\"=>'Ö',
\"\\x86\"=>'Ü',\"\\x87\"=>'á',\"\\x88\"=>'à',
\"\\x89\"=>'â',\"\\x8A\"=>'ä',\"\\x8B\"=>'ã',
\"\\x8C\"=>'å',\"\\x8D\"=>'ç',\"\\x8E\"=>'é',
\"\\x8F\"=>'è',\"\\x90\"=>'ê',\"\\x91\"=>'ë',
\"\\x92\"=>'í',\"\\x93\"=>'ì',\"\\x94\"=>'î',
\"\\x95\"=>'ï',\"\\x96\"=>'ñ',\"\\x97\"=>'ó',
\"\\x98\"=>'ò',\"\\x99\"=>'ô',\"\\x9A\"=>'ö',
\"\\x9B\"=>'õ',\"\\x9C\"=>'ú',\"\\x9D\"=>'ù',
\"\\x9E\"=>'û',\"\\x9F\"=>'ü',\"\\xA0\"=>'†',
\"\\xA1\"=>'°',\"\\xA2\"=>'¢',\"\\xA3\"=>'£',
\"\\xA4\"=>'§',\"\\xA5\"=>'•',\"\\xA6\"=>'¶',
\"\\xA7\"=>'ß',\"\\xA8\"=>'®',\"\\xA9\"=>'©',
\"\\xAA\"=>'™',\"\\xAB\"=>'´',\"\\xAC\"=>'¨',
\"\\xAD\"=>'≠',\"\\xAE\"=>'Æ',\"\\xAF\"=>'Ø',
\"\\xB0\"=>'∞',\"\\xB1\"=>'±',\"\\xB2\"=>'≤',
\"\\xB3\"=>'≥',\"\\xB4\"=>'¥',\"\\xB5\"=>'µ',
\"\\xB6\"=>'∂',\"\\xB7\"=>'∑',\"\\xB8\"=>'∏',
\"\\xB9\"=>'π',\"\\xBA\"=>'∫',\"\\xBB\"=>'ª',
\"\\xBC\"=>'º',\"\\xBD\"=>'Ω',\"\\xBE\"=>'æ',
\"\\xBF\"=>'ø',\"\\xC0\"=>'¿',\"\\xC1\"=>'¡',
\"\\xC2\"=>'¬',\"\\xC3\"=>'√',\"\\xC4\"=>'ƒ',
\"\\xC5\"=>'≈',\"\\xC6\"=>'∆',\"\\xC7\"=>'«',
\"\\xC8\"=>'»',\"\\xC9\"=>'…',\"\\xCA\"=>' ',
\"\\xCB\"=>'À',\"\\xCC\"=>'Ã',\"\\xCD\"=>'Õ',
\"\\xCE\"=>'Œ',\"\\xCF\"=>'œ',\"\\xD0\"=>'–',
\"\\xD1\"=>'—',\"\\xD2\"=>'“',\"\\xD3\"=>'”',
\"\\xD4\"=>'‘',\"\\xD5\"=>'’',\"\\xD6\"=>'÷',
\"\\xD7\"=>'◊',\"\\xD8\"=>'ÿ',\"\\xD9\"=>'Ÿ',
\"\\xDA\"=>'⁄',\"\\xDB\"=>'€',\"\\xDC\"=>'‹',
\"\\xDD\"=>'›',\"\\xDE\"=>'fi',\"\\xDF\"=>'fl',
\"\\xE0\"=>'‡',\"\\xE1\"=>'·',\"\\xE2\"=>'‚',
\"\\xE3\"=>'„',\"\\xE4\"=>'‰',\"\\xE5\"=>'Â',
\"\\xE6\"=>'Ê',\"\\xE7\"=>'Á',\"\\xE8\"=>'Ë',
\"\\xE9\"=>'È',\"\\xEA\"=>'Í',\"\\xEB\"=>'Î',
\"\\xEC\"=>'Ï',\"\\xED\"=>'Ì',\"\\xEE\"=>'Ó',
\"\\xEF\"=>'Ô',\"\\xF0\"=>'',\"\\xF1\"=>'Ò',
\"\\xF2\"=>'Ú',\"\\xF3\"=>'Û',\"\\xF4\"=>'Ù',
\"\\xF5\"=>'ı',\"\\xF6\"=>'ˆ',\"\\xF7\"=>'˜',
\"\\xF8\"=>'¯',\"\\xF9\"=>'˘',\"\\xFA\"=>'˙',
\"\\xFB\"=>'˚',\"\\xFC\"=>'¸',\"\\xFD\"=>'˝',
\"\\xFE\"=>'˛',\"\\xFF\"=>'ˇ' );}"
set AppleScript's text item delimiters to {ASCII character 10}
set perlscript to "" & paragraphs of perlscript
set AppleScript's text item delimiters to {""}
(* Write the perl script to the perl script file *)
open for access file fpl with write permission
set eof file fpl to 0
write perlscript to file fpl
close access file fpl
do shell script "perl " & fpluq & space & ftxtuq
set s to read file ftxt
do shell script "rm " & fpluq & space & ftxtuq
return s
end convertString
-- JD
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.