Evaluating XML in Memory



DataDirect XQuery® supports an extension expression named evaluate in memory that forces an expression to be evaluated in memory using XQuery directly, not using SQL. This is a simple way to use XQuery functionality that is not available in SQL.

For example, the following query fails and raises an error because DataDirect XQuery® cannot evaluate path expressions against XML in the database:

for $h in collection('HOLDINGSXML')/HOLDINGSXML
where $h/USERID eq 'Minollo'
return 
 $h/HOLDINGS[@COMPANY = 'Progress Software']

If we rewrite the query, using the evaluate-in-memory extension expression to force the XML to be evaluated in memory, the query succeeds:

for $h in collection('HOLDINGSXML')/HOLDINGSXML
let $holdings := (# ddtek:evaluate-in-memory #) {$h/XMLCOL)
where $h/USERID eq 'Minollo'
return 
 $holdings/SHARE[xs:string(@COMPANY) eq 'Progress 
 Software']

The result looks like this:

<HOLDINGS>
 <SHARE COMPANY="Progress Software" 
 USERID="Minollo">4000000</SHARE>
</HOLDINGS>