Hi Neven,
have a look at the [XQuery Module] especially at xquery:eval() or xquery:evaluate() to evaluate a given string. For security reasons you should perhaps bind your database as context, e.g. xquery:eval($query, map{ '' := db:open('crobib') }) If you’d just want to allow XPathes, you could make use of the fn:path() function, e.g. db:open('crobib')//*[path(). = $query]
Hope this helps Arve
[XQuery Module] http://docs.basex.org/wiki/XQuery_Module
On 11 Jan 2014, at 17:18, Neven Jovanović filologanoga@gmail.com wrote:
Hello,
my name is Neven Jovanovic, and I have beginner's problems with BaseX RESTXQ interface. We'd like to have a textarea form where users would compose their own XQueries to be executed over our database (just querying it, no updating etc). I have already written a cgi Perl script which does this through BaseX REST interface. Now I'd like to do the same with RESTXQ, but I'm missing something.
For testing purposes, we use the .zip version of 7.7.2 release, on Linux Mint Debian (locally), started with .basexhttp. Everything works OK, the db is there etc.
Here is the form added to the existing restxq.xqm:
<h3>Write an XQuery</h3> <p>Compose your own XQuery.</p> <form method="post" action="compoxq"> <p>XQuery:<br /> <textarea name="query" rows="5" cols="80"></textarea><br/> <input type="submit" /></p> </form>
Here is the function added to the restxq.xqm:
(:~ : A free-form XQuery. :) declare %rest:path("/compoxq") %rest:POST %rest:form-param("query","{$query}", "(no query)") function page:cpxq-postman( $query as xs:string*) { let $q := $query return element q { collection("crobib")//$q } };
Submitting the following form string: //*:person
I get these results at http://localhost:8984/compoxq:
<q> //*:person //*:person //*:person //*:person //*:person (lots more...) </q>
Some query obviously is being performed, but instead of results, I get the query string.
Appreciating your help,
Neven
Neven Jovanovic University of Zagreb Hrvatska / Croatia _______________________________________________ BaseX-Talk mailing list BaseX-Talk@mailman.uni-konstanz.de https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk