Purpose
XMLATTRIBUTES() specifies a collection of attributes for an XML element, and is a subexpression of XMLELEMENT.
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 | Optional. Specifies whether to force escape the attributes. If you do not specify it, the default value ENTITYESCAPING is used, indicating to force escape the attributes. |
| SCHEMACHECK|NOSCHEMACHECK | Optional. Specifies whether to perform a runtime check. If you do not specify it, the default value NOSCHEMACHECK is used, indicating that no check is performed. 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 the 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 with the content being col1.
obclient> SELECT XMLELEMENT(emp, XMLATTRIBUTES(col1 as "key")) FROM t1;
+--------------------------------------------+
| XMLELEMENT(EMP,XMLATTRIBUTES(COL1AS"KEY")) |
+--------------------------------------------+
| <EMP key="a"/>
|
+--------------------------------------------+
1 row in set