XMLTEXT scalar function
The XMLTEXT function returns an XML value with a single XQuery text node having the input argument as the content.
The schema is SYSIBM. The function name cannot be specified as a qualified name.
-
string-expression
- An expression whose value has a character string type: CHAR, VARCHAR or CLOB.
The data type of the result is XML. If the result of string-expression can be null, the result can be null; if the input value is null, the result is the null value. If the result of string-expression is an empty string, the result value is an empty text node.
Examples
- Example 1: Create a simple XMLTEXT query.
This query produces the following serialized result:VALUES( XMLTEXT( 'The stock symbol for Johnson&Johnson is JNJ.' ) )
Note that the '&' sign is mapped to '&' when a text node is serialized.1 --------------------------------------------------- The stock symbol for Johnson&Johnson is JNJ.
- Example 2: Use XMLTEXT with XMLAGG to construct mixed content.
Suppose that the content of table T is as follows:
seqno plaintext emphtext ------ ----------------------------------------------------------- ------------- 1 This query shows how to construct mixed content 2 using XMLAGG and XMLTEXT. Without XMLTEXT 3 XMLAGG will not have text nodes to group with other nodes, mixed content therefore, cannot generate
This query produces the following result:SELECT XMLELEMENT( NAME "para", XMLAGG( XMLCONCAT( XMLTEXT( PLAINTEXT ), XMLELEMENT( NAME "emphasis", EMPHTEXT ) ) ORDER BY SEQNO ), '.' ) AS "result" FROM T
result ------------------------------------------------------------------------------- <para>This query shows how to construct <emphasis>mixed content</emphasis> using XMLAGG and XMLTEXT. Without <emphasis>XMLTEXT</emphasis> , XMLAGG will not have text nodes to group with other nodes, therefore, cannot generate <emphasis>mixed content</emphasis>.</para>