Purpose
XMLATTRIBUTES is a subexpression of XMLELEMENT that specifies a collection of attributes for the generated XML elements.
Syntax
XMLATTRIBUTES
( [ ENTITYESCAPING | NOENTITYESCAPING ]
[ SCHEMACHECK | NOSCHEMACHECK ]
value_expr [ { AS c_alias } | { AS EVALNAME value_expr } ]
[, value_expr [ { AS c_alias } | { AS EVALNAME value_expr } ] ]...
)
Parameters
| Parameter | Description |
|---|---|
| ENTITYESCAPING|NOENTITYESCAPING | Specifies whether to escape the attributes. This parameter is optional. If you do not specify it, attributes are escaped by default. |
| SCHEMACHECK|NOSCHEMACHECK | Specifies whether to perform a runtime check on the attributes. This parameter is optional. If you do not specify it, the check is not performed by default. Currently, runtime checks are not supported. |
| value_expr | The expression that is evaluated to obtain the value, which is a string literal, for a generated attribute. |
| c_alias | The name of a generated attribute, which is a string literal. |
| EVALNAME | The keyword that specifies to name a generated attribute by using an expression that evaluates to a string literal. |
Return type
XMLATTRIBUTES is a clause of XMLELEMENT and cannot be used independently. Therefore, it does not have a return type.
Examples
Create a table named t1 and insert a data record.
obclient> CREATE TABLE t1(col1 varchar(10));
Query OK, 0 rows affected
obclient> INSERT INTO t1 VALUES('a');
Query OK, 1 row affected
Generate an attribute named key whose content is col1.
obclient> SELECT XMLELEMENT(emp, XMLATTRIBUTES(col1 as "key")) FROM t1;
+--------------------------------------------+
| XMLELEMENT(EMP,XMLATTRIBUTES(COL1AS"KEY")) |
+--------------------------------------------+
| <EMP key="a"/> |
+--------------------------------------------+
1 row in set