Dharmendra Kumar Singh
Dharmendra Kumar Singh

Reputation: 195

Dynamic combination search on specific path in BaseX

I want to perform dynamic combination (AND OR) search on the basis of the provided parameter by the user.

Search Combination Example:

( (title = "United States" or isbn = "2345371242192") and author ="Jhon" )

In the above query each parameter will look on their XPATH e.g. (item/tigroup/title, item/isbn), XPATH not provided by the user, i have to generate XPATH dynamically with search combination

How Combination query can be formed dynamically to pass it to the BaseX?

User can perform any kind of AND OR search, their can be multiple AND OR criteria

Any suggestions much appreciated

Upvotes: 0

Views: 100

Answers (1)

Christian Grün
Christian Grün

Reputation: 6229

With xquery:eval, strings can be evaluated as XQuery expression (see the documentation for more examples):

declare variable $QUERY := 'text()';

db:open('db')//*[xquery:eval($QUERY, map { '': . })]

Please note that it’s very risky to evaluate arbitrary strings as XQuery code. If the string contains user input, malicious strings may be passed on that do unexpected things. In the example above, a malicious string could be a file operation (e.g., file:delete(.)), or a query that runs very long and blocks your system.

Upvotes: 0

Related Questions