How to: |
The XMLDECOD function decodes the following five standard XML-encoded characters when they are encountered in a string:
Character Name |
Character |
XML-Encoded Representation |
---|---|---|
ampersand |
& |
& |
greater than symbol |
> |
> |
less than symbol |
< |
< |
double quotation mark |
" |
" |
single quotation mark (apostrophe) |
' |
' |
XMLDECOD(inlength, source_string, outlength, output)
where:
Integer
Is the length of the field containing the source character string, or a field that contains the length.
Alphanumeric
Is the name of the field containing the source character string or the string enclosed in single quotation marks (').
Integer
Is the length of the output character string, or a field that contains the length.
Integer
Is the field that contains the result, or the format of the output value enclosed in single quotation marks.
The file XMLFUNCS is a .csv file that contains some unencoded characters and some XML-encoded characters. The Master File is:
FILE = XMLFUNCS, SUFFIX=COM,$ SEGNAME = SEG01, SEGTYPE=S1,$ FIELD=INSTRING, ALIAS=CHARS, USAGE=A30,ACTUAL=A30,$
The contents of the file follow:
CHARS: & < > ,$ ENCODED: & > ,$ ENCODED: " ' ,$ MIXED: & < > ,$
XMLDECOD decodes any of the supported XML-encoded characters. Note that some viewers automatically decode the encoded values for display, so the output is produced in a plain text format (FORMAT WP):
FILEDEF XMLFUNCS DISK xmlfuncs.csv DEFINE FILE XMLFUNCS OUTSTRING/A30=XMLDECOD(30,INSTRING,30,'A30'); END TABLE FILE XMLFUNCS PRINT INSTRING OUTSTRING ON TABLE PCHOLD FORMAT WP ON TABLE SET PAGE NOPAGE
In the output string, XML-encoded characters have been decoded, and characters that were not encoded have been left as they were in the input string:
INSTRING OUTSTRING -------- --------- CHARS: & < > CHARS: & < > ENCODED: & > ENCODED: & > ENCODED: " ' ENCODED: " ' MIXED: & < > MIXED: & < >