One more thought on using eval:
The xquery:eval function in BaseX has been optimized a lot over time. There are even use cases in which it will be evaluated faster than code without eval. An example:
Query 1:
for $db in ('with-index', 'without-index') return db:open($db)//*[text() = 'please']
Query 2:
for $db in ('with-index', 'without-index') let $query := "//*[text() = 'please']" return xquery:eval($query, map { "": db:open($db) })
In these queries, two databases will be opened, one with text index, one without. In Query 1, it is (currently) not possible for the optimizer to rewrite the path expression for index access. This is different for Query 2: In the first call of xquery:eval, the index will be used, because it will be known at runtime that the referenced database has a text index.
If one is aware of the obvious drawbacks of using eval (code injection, query strings cannot be parsed at compile time, ...), it can be a good choice (and there have already been thoughts to include it in a future version of the official W3C spec).
Christian
On Sat, Nov 15, 2014 at 1:27 PM, Marc van Grootel marc.van.grootel@gmail.com wrote:
Thanks Marco and Andy.
I will go with XPath selectors and eval for now. John Snelson's library is indeed interesting and a while ago I tried the parser part for parsing XQuery into XML. I don't either understand it fully but it seems to do it's job.
--Marc