XML from Data Base Examples tutorial
Making a Forest of XML elements XMLFOREST() function

## XMLFOREST() function. Overview

XMLFOREST produces a forest of XML elements from the given list of arguments. The arguments may be string expressions with optional aliases. If string expression is a column name, then you can omit the 'AS clause', and Virtuoso uses the partially escaped form of the column name as the name of the enclosing tag. If the expression evaluates to NULL, then no element is created for that expression. If none of the element is created, then the function returns null.

## Example 1

This example produces a forest of five (or four) elements ('FName', 'LName', 'Title', 'Region' - if there is a value, 'str') with the text content from 'FirstName', 'LastName', 'Title', and 'Region' columns of the "Employees" table and 'simple_string' string, and concatenates the elements produced. Five elements are created for the employee with "EmployeeId" = 1 and four elements are created for the employee with "EmployeeId" = 5:

    select XMLFOREST ("FirstName" as "FName", "LastName" as "LName", "Title", "Region", 'simple_string' as "str")
      from "Demo"."demo"."Employees"
      where "EmployeeId" = 1 or "EmployeeId" = 5