The XMLATTRIBUTES function constructs XML attributes from the arguments.
>>-XMLATTRIBUTES------------------------------------------------> .-,--------------------------------------------------. V | >--(----attribute-value-expression--+--------------------+-+--)->< '-AS--attribute-name-'
The schema is SYSIBM. The function name cannot be specified as a qualified name.
This function can only be used as an argument of the XMLELEMENT function. The result is an XML sequence containing an XQuery attribute node for each non-null input value.
If attribute-name is not specified, attribute-value-expression must be a column name (SQLSTATE 42703). The attribute name is created from the column name using the fully escaped mapping from a column name to an XML attribute name.
The data type of the result is XML. If the result of attribute-value-expression can be null, the result can be null; if the result of every attribute-value-expression is null, the result is the null value.
SELECT E.EMPNO, XMLELEMENT(
NAME "Emp",
XMLATTRIBUTES(
E.EMPNO, E.FIRSTNME ||' '|| E.LASTNAME AS "name"
)
)
AS "Result"
FROM EMPLOYEE E WHERE E.EDLEVEL = 12
This
query produces the following result: EMPNO Result
000290 <Emp EMPNO="000290" name="JOHN PARKER"></Emp>
000310 <Emp EMPNO="000310" name="MAUDE SETRIGHT"></Emp>
200310 <Emp EMPNO="200310" name="MICHELLE SPRINGER"></Emp>
VALUES XMLELEMENT(
NAME "size",
XMLNAMESPACES(
'http://www.w3.org/2001/XMLSchema-instance' AS "xsi",
'http://www.w3.org/2001/XMLSchema' AS "xsd"
),
XMLATTRIBUTES(
'xsd:string' AS "xsi:type"
), '1'
)
This query produces the following result: <size xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xsi:type="xsd:string">1</size>