CF_XQuery

XQuery for ColdFusion

<CF_XQuery>

This tag executes an XQuery expression a database or any other url and returns any result as xml.

Example 1 – Querying a server database:

<cf_xquery name=”myquery” datasource=”db”>
for $i in document("$documentName")
return $i
</cf_xquery
>

Example 2 – Querying a url:

<cf_xquery name=”myquery”>
for $i in document("http://www.google.com")
return $i
</cf_xquery
>

Attributes:

NameTypeRequiredDescription
namestringyesName of the xml result returned by the Xquery expression
datasourcestringnoThis is the name of a CFXQuery database. If this is not specified, the it is assumed that the Xquery expression should be executed against a url.
servernamestringnoThe IP address of the CFXQuery server that the XQuery expression should be executed against. Default is 'localhost'. This can include a port number as well (default is 5050)
usernamestringnoThe CFXQuery database username if secured
passwordstringnoThe CFXQuery database password if secured
returnAsStringboolean no Specifies whether the tag returns a ColdFusion xml object or a string of xml. See usage notes below. Default is false


Usage:

By default, this tag returns the result of any XQuery expression as a ColdFusion XML object. Since an Xquery/XPath expression doesn't necessarily returned well formed XML (the results may not include a root node), then this tag appends a new root node.

This node has the element name :

<cf_xquery_result>
 <xml_returned_from_xquery ...>
</cf_xquery_result
>

The usage of <CF_XQuery> does have a number of limitiations. Currently it is not possible to include unevaluated ColdFusion functions within a statement. It is possible to include unevaluated variables of any scope. Below are some examples:

allowed#variables.expression#
allowed#session.expression#
allowed#object.getName()#
not allowed#trim(variables.forename)#

More Information