• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: XML beginner question (about special characters display)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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\"=>'&#xC4;',\"\\x81\"=>'&#xC5;',\"\\x82\"=>'&#xC7;',
\"\\x83\"=>'&#xC9;',\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3;',
\"\\xEF\"=>'&#xD4;',\"\\xF0\"=>'&#xF8FF;',\"\\xF1\"=>'&#xD2;',
\"\\xF2\"=>'&#xDA;',\"\\xF3\"=>'&#xDB;',\"\\xF4\"=>'&#xD9;',
\"\\xF5\"=>'&#x131;',\"\\xF6\"=>'&#x2C6;',\"\\xF7\"=>'&#x2DC;',
\"\\xF8\"=>'&#xAF;',\"\\xF9\"=>'&#x2D8;',\"\\xFA\"=>'&#x2D9;',
\"\\xFB\"=>'&#x2DA;',\"\\xFC\"=>'&#xB8;',\"\\xFD\"=>'&#x2DD;',
\"\\xFE\"=>'&#x2DB;',\"\\xFF\"=>'&#x2C7;' );}"
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.

References: 
 >Re: XML beginner question (about special characters display) (From: JJ <email@hidden>)

  • Prev by Date: Adding AppleScript ability to a java application
  • Next by Date: Re: file list with Finder
  • Previous by thread: Re: XML beginner question (about special characters display)
  • Next by thread: Re: XML beginner question (about special characters display)
  • Index(es):
    • Date
    • Thread