views:

24

answers:

1

With XQuery you can use library modules within your query. They can be imported via

import module namespace mynamespace = 'com.mynamespace' at 'filename.xq';

The question is: is there a way to determine which file is associated with the module namespace so that the programmer can decide dynamically?

For example, my dynamic configuration tells that mynamespace should be associated with filename1.xq ...

import module namespace mynamespace = 'com.mynamespace' at 'filename1.xq';

and then, perhaps after some user clicks, myfile2.xq should be used?

import module namespace mynamespace = 'com.mynamespace' at 'myfile2.xq';

If you use Java & Saxon, you can use perhaps the ModuleURIResolver, but the resolver is part of the commercial, non-free Enterprise Edition. Is there a workaround for this problem if you are in a Java environment?

A: 

Option 1

You may want to check with eval/invoke type of XQuery-(Implementation) specific APIs.

In MarkLogic XQuery API you may find

xdmp:eval("XQUERY AS STRING") or xdmp:invoke(function pointer, params) helps to achieve reflection type of user implementation.

Option 2 try to have some Procedure language based functional design patterns to resolve such issues.

REMEMBER: Using "eval" type APIs you have to be very cautious about XQuery Injection too.

kadalamittai