(*
Converts non xml friendly characters on the clipboard to equivalent character entities.
-- So < ' " & > becomes &#60; &#39; &#34; &#38; &#62;
--CBT
*)

do shell script "
pbpaste | 
perl -0777pwe 's/([\"\\47&<>])/sprintf(\"&#%d;\", ord($1))/eg' |  
pbcopy
"

open txt2xml in the applescript editor