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

SQL Anywhere 11.0.1 (Français) » SQL Anywhere Server - SQL Reference » Using SQL » SQL functions » SQL functions (P-Z)


XMLGEN function [String]

Generates an XML value based on an XQuery constructor.

XMLGEN( xquery-constructor, content-expression [ AS variable-name ],... )
  • xquery-constructor   An XQuery constructor. The XQuery constructor is an item defined in the XQuery language. It gives a syntax for constructing XML elements based on XQuery expressions. The xquery-constructor argument must be a well-formed XML document with one or more variable references. A variable reference is enclosed in curly braces and must be prefixed with a $ and have no surrounding white space. For example:
    SELECT XMLGEN( '<a>{$x}</a>', 1 AS x );

  • content-expression   A variable. You can specify multiple content-expression arguments. The optional variable-name argument is used to name the variable. For example,
    SELECT XMLGEN( '<emp EmployeeID="{$EmployeeID}"><StartDate>{$x}</StartDate></emp>',
                   EmployeeID, StartDate 
                   AS x )
    FROM Employees;




Computed constructors as defined in the XQuery specification are not supported by the XMLGEN function.

When you execute a query that contains an XMLGEN function, data in BINARY, LONG BINARY, IMAGE, and VARBINARY columns is automatically returned in base64-encoded format.

Element content is always escaped unless the data type is XML. Illegal XML element and attribute names are also escaped.

For information about escaping and the XMLGEN function, see Invalid names and SQL/XML.

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


The following example generates <emp>, <Surname>, <GivenName>, and <StartDate> elements for each employee.

SELECT XMLGEN( '<emp EmployeeID="{$EmployeeID}">
              ) AS employee_list
FROM Employees;