In this video, we'll explore the powerful world of XQuery and how to execute it directly from the command line. Whether you're a ...
Running XQuery from the command line can be done using various XQuery processors. Here’s a step-by-step guide using two popular processors: BaseX and eXist-db.
Change to the BaseX directory where you extracted the files:
cd path/to/basex
Start the BaseX command line interface:
./basex
For Windows, you may need to run:
basex.bat
You can run an XQuery directly in the BaseX shell. For example:
XQUERY "for $i in (1 to 10) return $i"
Alternatively, you can run an XQuery from a file. Create a file named query.xq
:
for $i in (1 to 10) return $i
Then execute it using:
./basex query.xq
Change to the eXist-db directory where you extracted the files:
cd path/to/exist-db
Start the eXist-db server:
./bin/startserver
For Windows, you may run:
bin\startserver.bat
You can execute XQuery using the curl
command to send a request to the eXist-db REST API. For example:
curl -X POST -H "Content-Type: application/xquery" -d "for \$i in (1 to 10) return \$i" http://localhost:8080/exist/rest/db/xquery
By following these steps, you can efficiently run XQuery from the command line using either BaseX or eXist-db. Make sure to modify file paths and commands according to your system setup. This allows you to harness the power of XQuery for various data manipulation tasks directly from your terminal.