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:
| Name | Type | Required | Description |
|---|---|---|---|
| name | string | yes | Name of the xml result returned by the Xquery expression |
| datasource | string | no | This 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. |
| servername | string | no | The 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) |
| username | string | no | The CFXQuery database username if secured |
| password | string | no | The CFXQuery database password if secured |
| returnAsString | boolean | 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:
#variables.expression#
#session.expression#
#object.getName()#
#trim(variables.forename)#