<!--
 -  
 -  This file is part of the OpenLink Software Virtuoso Open-Source (VOS)
 -  project.
 -  
 -  Copyright (C) 1998-2018 OpenLink Software
 -  
 -  This project is free software; you can redistribute it and/or modify it
 -  under the terms of the GNU General Public License as published by the
 -  Free Software Foundation; only version 2 of the License, dated June 1991.
 -  
 -  This program is distributed in the hope that it will be useful, but
 -  WITHOUT ANY WARRANTY; without even the implied warranty of
 -  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 -  General Public License for more details.
 -  
 -  You should have received a copy of the GNU General Public License along
 -  with this program; if not, write to the Free Software Foundation, Inc.,
 -  51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
 -  
 -  
-->
<?xml version="1.0" encoding="ISO-8859-1"?>
<refentry id="SX-F-1">
  <refmeta>
    <refentrytitle>XML from Data Base Examples</refentrytitle>
    <refmiscinfo>tutorial</refmiscinfo>
  </refmeta>
  <refnamediv>
    <refname>Making a Forest of XML elements</refname>
    <refpurpose>XMLFOREST() function</refpurpose>
  </refnamediv>

<refsect1 id="SX-F-1a">
<title>XMLFOREST() function. Overview</title>
<para>
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 &apos;AS clause&apos;, 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.
</para>
</refsect1>

<refsect1 id="SX-F-1b">
<title>Example 1</title>
<para>This example produces a forest of five (or four) elements (&apos;FName&apos;, &apos;LName&apos;, &apos;Title&apos;, &apos;Region&apos; - if there is a value,  &apos;str&apos;) 
with the text content from &apos;FirstName&apos;, &apos;LastName&apos;, &apos;Title&apos;, and &apos;Region&apos; 
columns of the "Employees" table and &apos;simple_string&apos; 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:
</para>
<programlisting>
select XMLFOREST ("FirstName" as "FName", "LastName" as "LName", "Title", "Region", 'simple_string' as "str")
  from "Demo"."demo"."Employees" 
  where "EmployeeId" = 1 or "EmployeeId" = 5
</programlisting>
</refsect1>

</refentry>
