HTML Widget: convert html to text and text to html

Author: edu@kornmann.com (Edu Kornmann)

With Uniface 9 Client/Server and HTML Widget: Want to convert text to html in 1 go as in next example:   stringTextVar = "value1 < value2"   stringHtmlVar = ""   $textToHtml( stringTextVar , stringHtmlVar ) Result: stringHtmlVar = "value1 &lt; value2" And also back again from html into text. Is there a Uniface function which do the trick? For example $string(...) or $encode/$decode ?

7 Comments

  1. Hi Edu, nice to see some old uniface experts like you are still in unifaceland. Couple of years ago when I experimented with the HTMLwidget, I created my own global function which translates the critical characters into their &...; counterpart and vice versa. Important: you have to convert the ampersand at first nebause ampersand is in all the replacements. Greetings from Frankfurt/Germany, Uli


    Author: ulrich-merkel (ulrichmerkel@web.de)
  2. Hi Ulrich, nice to see you very active on this forum for so long time. Plan to be more active too... But, currently found solution using HTML PRATT divice table, but then have to print to file, load file into variable. Some other way is the old school "translation tabel on database I/O", but that is not the direction I want to go. There are lot's of 3GL DLL's to use, but wish to use Uniface native functions. Greetings from Callantsoog, near the beach. Edu.


    Author: Edu Kornmann (edu@kornmann.com)
  3. Just to be sure: the URL option of $encode is not what you are looking for?


    Author: Theo Neeskens (tneeskens@itblockz.nl)
  4. Hi Edu, in 2008 I created my own XMLwriter which performs much better than the one officially provided.   There I used a Function ("returns string") to convert from and to HTML-entities. Actually, these are just a set of $replace starting "&" to "&amp;" Thre decoding has to be done in reverse order so "&amp;" to "&" is the last one.   Because it's not that easy to show HTML-like code in this forum: if you want the code, send me a mesage, Uli


    Author: ulrich-merkel (ulrichmerkel@web.de)
  5. Hi Edu, The struct datatype will do some XML encoding for you

    entry lpHTMLencode
       returns string
       params
          string pString : IN
       endParams
       variables
          struct vStruct
       endvariables
    
       vStruct->x = pString
       structtoxml pString, vStruct
       return pString[4,$length(pString)-5]
    end
    
    entry lpHTMLdecode
       returns string
       params
          string pString : IN
       endParams
       variables
          struct vStruct
       endvariables
    
       xmltostruct vStruct, $concat("<x>", pString, "</x>")
       return vStruct->x
    end

      I am pretty sure there is a way to do this without the need for a dummy x node


    Author: Mike Taylor (michael.taylor@uniface.com)
  6. Hi Mike,   Thanks for this suggestion. Hoped this would answer my question. So made a test with the next string buffer: ==== String content in buffer before conversion to HTML style text ============ double quotes                                    :  "    ampersand                                        :  &    single quote                                     :  '    slash                                            :  /    less than sign                                   :  <    greater than sign                                :  >    at symbol                                        :  @    opening bracket                                  :  [    backslash                                        :  \    closing bracket                                  :  ]    caret - circumflex                               :  ^    underscore                                       :  _    grave accent                                     :  `    opening brace                                    :  {    vertical bar                                     :  |    closing brace                                    :  }    equivalency sign - tilde                         :  ~    inverted exclamation mark                        :  ¡    cent sign                                        :  ¢    pound sign                                       :  £    currency sign                                    :  ¤    yen sign                                         :  ¥    broken vertical bar                              :  ¦    section sign                                     :  §    spacing diaeresis - umlaut                       :  ¨    copyright sign                                   :  ©    feminine ordinal indicator                       :  ª    left double angle quotes                         :  «    not sign                                         :  ¬    soft hyphen                                      :  ­    registered trade mark sign                       :  ®    spacing macron - overline                        :  ¯    degree sign                                      :  °    plus-or-minus sign                               :  ±    superscript two - squared                        :  ²    superscript three - cubed                        :  ³    acute accent - spacing acute                     :  ´    micro sign                                       :  µ    pilcrow sign - paragraph sign                    :  ¶    middle dot - Georgian comma                      :  ·    spacing cedilla                                  :  ¸    superscript one                                  :  ¹    masculine ordinal indicator                      :  º    right double angle quotes                        :  »    fraction one quarter                             :  ¼    fraction one half                                :  ½    fraction three quarters                          :  ¾    inverted question mark                           :  ¿    latin capital letter A with grave                :  À    latin capital letter A with acute                :  Á    latin capital letter A with circumflex           :      latin capital letter A with tilde                :  à   latin capital letter A with diaeresis            :  Ä    latin capital letter A with ring above           :  Å    latin capital letter AE                          :  Æ    latin capital letter C with cedilla              :  Ç    latin capital letter E with grave                :  È    latin capital letter E with acute                :  É    latin capital letter E with circumflex           :  Ê    latin capital letter E with diaeresis            :  Ë    latin capital letter I with grave                :  Ì    latin capital letter I with acute                :  Í    latin capital letter I with circumflex           :  Π   latin capital letter I with diaeresis            :  Ï    latin capital letter ETH                         :  Р   latin capital letter N with tilde                :  Ñ    latin capital letter O with grave                :  Ò    latin capital letter O with acute                :  Ó    latin capital letter O with circumflex           :  Ô    latin capital letter O with tilde                :  Õ    latin capital letter O with diaeresis            :  Ö    multiplication sign                              :  ×    latin capital letter O with slash                :  Ø    latin capital letter U with grave                :  Ù    latin capital letter U with acute                :  Ú    latin capital letter U with circumflex           :  Û    latin capital letter U with diaeresis            :  Ü    latin capital letter Y with acute                :  Ý    latin capital letter THORN                       :  Þ    latin small letter sharp s - ess-zed             :  ß    latin small letter a with grave                  :  à    latin small letter a with acute                  :  á    latin small letter a with circumflex             :  â    latin small letter a with tilde                  :  ã    latin small letter a with diaeresis              :  ä    latin small letter a with ring above             :  å    latin small letter ae                            :  æ    latin small letter c with cedilla                :  ç    latin small letter e with grave                  :  è    latin small letter e with acute                  :  é    latin small letter e with circumflex             :  ê    latin small letter e with diaeresis              :  ë    latin small letter i with grave                  :  ì    latin small letter i with acute                  :  í    latin small letter i with circumflex             :  î    latin small letter i with diaeresis              :  ï    latin small letter eth                           :  ð    latin small letter n with tilde                  :  ñ    latin small letter o with grave                  :  ò    latin small letter o with acute                  :  ó    latin small letter o with circumflex             :  ô    latin small letter o with tilde                  :  õ    latin small letter o with diaeresis              :  ö    division sign                                    :  ÷    latin small letter o with slash                  :  ø    latin small letter u with grave                  :  ù    latin small letter u with acute                  :  ú    latin small letter u with circumflex             :  û    latin small letter u with diaeresis              :  ü    latin small letter y with acute                  :  ý    latin small letter thorn                         :  þ    latin small letter y with diaeresis              :  ÿ    euro sign                                        :  €    ==== End of string received from text file =============   What I hoped to received back is the next buffer: === Expected string content after lpHtmlEncode  =======================     double quotes                                    :  &quot;     ampersand                                        :  &amp;      single quote                                     :  '          slash                                            :  /          less than sign                                   :  &lt;       greater than sign                                :  &gt;       at symbol                                        :  @          opening bracket                                  :  [          backslash                                        :  \          closing bracket                                  :  ]          caret - circumflex                               :  ^          underscore                                       :  _          grave accent                                     :  `          opening brace                                    :  {          vertical bar                                     :  |          closing brace                                    :  }          equivalency sign - tilde                         :  ~          inverted exclamation mark                        :  &iexcl;    cent sign                                        :  &cent;     pound sign                                       :  &pound;    currency sign                                    :  &curren;   yen sign                                         :  &yen;      broken vertical bar                              :  &brvbar;   section sign                                     :  &sect;     spacing diaeresis - umlaut                       :  &uml;      copyright sign                                   :  &copy;     feminine ordinal indicator                       :  &ordf;     left double angle quotes                         :  &laquo;    not sign                                         :  &not;      soft hyphen                                      :  &shy;      registered trade mark sign                       :  &reg;      spacing macron - overline                        :  &macr;     degree sign                                      :  &deg;      plus-or-minus sign                               :  &plusmn;   superscript two - squared                        :  &sup2;     superscript three - cubed                        :  &sup3;     acute accent - spacing acute                     :  &acute;    micro sign                                       :  &micro;    pilcrow sign - paragraph sign                    :  &para;     middle dot - Georgian comma                      :  &middot;   spacing cedilla                                  :  &cedil;    superscript one                                  :  &sup1;     masculine ordinal indicator                      :  &ordm;     right double angle quotes                        :  &raquo;    fraction one quarter                             :  &frac14;   fraction one half                                :  &frac12;   fraction three quarters                          :  &frac34;   inverted question mark                           :  &iquest;   latin capital letter A with grave                :  &Agrave;   latin capital letter A with acute                :  &Aacute;   latin capital letter A with circumflex           :  &Acirc;    latin capital letter A with tilde                :  &Atilde;   latin capital letter A with diaeresis            :  &Auml;     latin capital letter A with ring above           :  &Aring;    latin capital letter AE                          :  &AElig;    latin capital letter C with cedilla              :  &Ccedil;   latin capital letter E with grave                :  &Egrave;   latin capital letter E with acute                :  &Eacute;   latin capital letter E with circumflex           :  &Ecirc;    latin capital letter E with diaeresis            :  &Euml;     latin capital letter I with grave                :  &Igrave;   latin capital letter I with acute                :  &Iacute;   latin capital letter I with circumflex           :  &Icirc;    latin capital letter I with diaeresis            :  &Iuml;     latin capital letter ETH                         :  &ETH;      latin capital letter N with tilde                :  &Ntilde;   latin capital letter O with grave                :  &Ograve;   latin capital letter O with acute                :  &Oacute;   latin capital letter O with circumflex           :  &Ocirc;    latin capital letter O with tilde                :  &Otilde;   latin capital letter O with diaeresis            :  &Ouml;     multiplication sign                              :  &times;    latin capital letter O with slash                :  &Oslash;   latin capital letter U with grave                :  &Ugrave;   latin capital letter U with acute                :  &Uacute;   latin capital letter U with circumflex           :  &Ucirc;    latin capital letter U with diaeresis            :  &Uuml;     latin capital letter Y with acute                :  &Yacute;   latin capital letter THORN                       :  &THORN;    latin small letter sharp s - ess-zed             :  &szlig;    latin small letter a with grave                  :  &agrave;   latin small letter a with acute                  :  &aacute;   latin small letter a with circumflex             :  &acirc;    latin small letter a with tilde                  :  &atilde;   latin small letter a with diaeresis              :  &auml;     latin small letter a with ring above             :  &aring;    latin small letter ae                            :  &aelig;    latin small letter c with cedilla                :  &ccedil;   latin small letter e with grave                  :  &egrave;   latin small letter e with acute                  :  &eacute;   latin small letter e with circumflex             :  &ecirc;    latin small letter e with diaeresis              :  &euml;     latin small letter i with grave                  :  &igrave;   latin small letter i with acute                  :  &iacute;   latin small letter i with circumflex             :  &icirc;    latin small letter i with diaeresis              :  &iuml;     latin small letter eth                           :  &eth;      latin small letter n with tilde                  :  &ntilde;   latin small letter o with grave                  :  &ograve;   latin small letter o with acute                  :  &oacute;   latin small letter o with circumflex             :  &ocirc;    latin small letter o with tilde                  :  &otilde;   latin small letter o with diaeresis              :  &ouml;     division sign                                    :  &divide;   latin small letter o with slash                  :  &oslash;   latin small letter u with grave                  :  &ugrave;   latin small letter u with acute                  :  &uacute;   latin small letter u with circumflex             :  &ucirc;    latin small letter u with diaeresis              :  &uuml;     latin small letter y with acute                  :  &yacute;   latin small letter thorn                         :  &thorn;    latin small letter y with diaeresis              :  &yuml;     euro sign                                        :  &euro;     === end string content after lpHtmlEncode =======================   But, the only conversion made is: ampersand                                        :  &amp;      less than sign                                   :  &lt;       greater than sign                                :  &gt;       The rest is not converted. Probably that is no problem for HTML viewers and should it not be converted to the HTML equivalent?


    Author: Edu Kornmann (edu@kornmann.com)
  7. Hi Edu, so if you want a function which passes your test and you want it NOW, create your own one (as I suggested earlier). Just a function with a string parameter which returns a string and has a couple of $replace statements in the body.   Nice Christmas and a Happy New Year from Frankfurt/Germany, Uli


    Author: ulrich-merkel (ulrichmerkel@web.de)