HtmlDecode - ObjectVision/GeoDMS GitHub Wiki

String functions HtmlDecode

The HtmlDecode function decodes HTML-encoded strings back to their original form.

syntax

HtmlDecode(strings: E->String) -> E->String

definition

Converts HTML-encoded strings back to their original format by replacing HTML entity references with the corresponding characters:

Entity Character
&lt; <
&gt; >
&amp; &
&quot; "
&apos; '
&nbsp; no-break space (U+00A0, two bytes in UTF-8)

The first five are the predefined XML/HTML entities that HtmlEncode produces, so HtmlDecode(HtmlEncode(x)) returns x. &nbsp; is accepted as well because it is ubiquitous in HTML, although HtmlEncode never produces it.

Also decodes numeric character references, decimal &#60; as well as hexadecimal &#x3C;, emitting the code point as UTF-8.

Anything that is not a reference this function knows is copied through verbatim rather than being an error: an unknown name (&unknown;), an unterminated reference (&amp x) and an out-of-range numeric reference all stay as they are, since that is what the input meant literally. &amp;lt; therefore decodes to &lt;, not to <: decoding is applied once, not repeatedly.

arguments

argument description type
strings HTML-encoded strings to decode E->String

performance

Time complexity: O(n × L) where n is the number of strings and L is the average string length.

Decoded strings are typically slightly shorter than input strings.

example

unit<uint32> HtmlContent: nrofrows = 3;
attribute<String> encoded (HtmlContent) := union_data(HtmlContent,
    'Hello &lt;world&gt;',
    'A &amp; B',
    'Quote: &quot;test&quot;'
);

attribute<String> decoded (HtmlContent) := HtmlDecode(encoded);
// decoded = {'Hello <world>', 'A & B', 'Quote: "test"'}

use cases

  • Processing data extracted from HTML sources
  • Converting HTML content to plain text
  • Cleaning up HTML entity artifacts in imported data

see also

since version

20.13.0

⚠️ **GitHub.com Fallback** ⚠️