XMLFOREST function [String]

Generates a forest of XML elements.

Syntax
XMLFOREST( element-content-expression [ AS element-name ],... )
Parameters
  • element-content-expression   A string. An element is generated for each element-content-expression argument that is specified. The element-content-expression value becomes the content of the element. For example, if you specify the EmployeeID column from the Employees table for this argument, then an <EmployeeID> element containing an EmployeeID value is generated for each value in the table.

    Specify the element-name argument if you want to assign a name other than the element-content-expression to the element, otherwise the element name defaults to the element-content-expression name.

Returns

XML

Remarks

Produces a forest of XML elements. In the unparsed XML document, a forest refers to the multiple root nodes within the document. When all the arguments to the XMLFOREST function are NULL, a NULL value is returned. If only some values are NULL, the NULL values are omitted from the result. Element content is always quoted unless the data type is XML. You cannot specify attributes using the XMLFOREST function. Use the XMLELEMENT function if you want to specify attributes for generated elements.

For more information about the XMLELEMENT function, see XMLELEMENT function [String].

Element names are escaped unless the data type is XML.

If you require a well-formed XML document, you must ensure that your query is written so that a single root element is generated.

Data in BINARY, LONG BINARY, IMAGE, and VARBINARY columns is automatically returned in base64-encoded format when you execute a query that contains XMLFOREST.

See also
Standards and compatibility
  • Part of the SQL/XML draft standard.

Example

The following statement produces an XML element for the first and last name of each employee.

SELECT EmployeeID,
       XMLFOREST( GivenName, Surname )
       AS "Employee Name"
FROM Employees;