Reference Guide > TDV Support for SQL Functions > TDV-Supported XML Functions > XMLQUERY
 
XMLQUERY
The XMLQUERY function returns an XML value from the evaluation of an XQuery expression. This function accepts one character literal argument, which is the XML query.
Syntax
XMLQUERY ( <XQuery_expression> [ <XML_query_argument list> ]
[ <XML_returning_clause>
[ <XML_query_returning_mechanism> ] ]
<XML_query_empty_handling_option>
)
Remarks
Multiple arguments can be passed as input to the XML query.
Each argument must be an XML data type, or be castable to an XML data type.
Each argument can be followed by an optional identifier which gives the argument a variable name.
If an argument is missing the identifier, the argument becomes the context item.
Only one context item per XMLQUERY function can exist.
Each input must be resolved to an XML data type and must be aliased.
Each alias must be unique, and is case-sensitive.
TDV Server uses the Saxon as its XQuery parser. Saxon requires that all XQuery variables be declared as external variables in the XQuery. (This is not an ANSI requirement.)
TDV Server also requires all noncontext item variables to be declared in the XQUERY text. (This is not ANSI-specific.)
Variables can be declared through the format declare variable $<name> external; where <name> is the name of the variable. Multiple declarations can be separated by a semicolon.
XQuery keywords should be written in lowercase.
The XML-passing mechanism is accepted but ignored.
If the empty handling option is NULL ON EMPTY, NULL is returned if the result of the XQuery is an empty element.
Example
XMLQUERY ('declare variable $c external; for $i in $c
where $i /PDName = "Jean Morgan"
order by $i/PDName
return $i/PDName' passing XMLELEMENT(name PDRecord, XMLELEMENT(name PDName, 'Jean Morgan')) as c )
 
This results in <PDName>Jean\ Morgan</PDName>.