XMLAttributes() function

The XMLAttributes() function constructs an XML attribute object. This object is not a valid XML object: rather, you must assign it as an attribute value of an XMLElement() function.

Syntax

The XMLAttributes() function has the following syntax:
XML_Attrib = XMLAttributes(varchar name, varchar value);

The name value specifies the name of the XML attribute to construct.

The value value specifies the value of the XML attribute to construct.

Returns

The function returns an XML attribute object.

Example

The following example produces an Emp element for each employee, with an ID and name attribute:
SELECT XMLELEMENT ( 'Emp',
XMLATTRIBUTES (e.id,e.fname ||' ' || e.lname AS "name")) AS "result"
FROM employees e
WHERE employee_id > 200;
This query produces an XML result fragment. An example follows:
<Emp ID="1001" name="John Smith"/>
<Emp ID="1206" name="Jane Doe"/>