Click here to view and discuss this page in DocCommentXchange. In the future, you will be sent there automatically.

SQL Anywhere 10.0.1 » SQL Anywhere Server - SQL Usage » Using XML in the Database » Using SQL/XML to obtain query results as XML

Using the XMLELEMENT function Next Page

Using the XMLFOREST function


XMLFOREST constructs a forest of XML elements. An element is produced for each XMLFOREST argument.

The following query produces an <item_description> element, with <name>, <color>, and <price> elements:

SELECT ID, XMLELEMENT( NAME item_description,
                       XMLFOREST( Name as name,
                                  Color as color,
                                  UnitPrice AS price )
                      ) AS product_info
FROM Products
WHERE ID > 400;

The following result is generated by this query:

ID

product_info

401
<item_description>
 <name>Baseball Cap</name>
 <color>White</color>
 <price>10.00</price>
</item_description>
500
<item_description>
 <name>Visor</name>
 <color>White</color>
 <price>7.00</price>
</item_description>
501
<item_description>
 <name>Visor</name>
 <color>Black</color>
 <price>7.00</price>
</item_description>
...

...

For more information, see XMLFOREST function [String].