简体   繁体   中英

How do I pass xquery through eXist-db's REST api?

I understand how to use Xpath

http://localhost:8080/exist/rest/db/movies?_query=//movie[title=%22Spider-Man%22]/node()

But how to pass an xquery query? I keep reading everywhere that the REST api is for both xpath and xquery but I can't get my query to work. Here is what I'm trying to pass as an example (I've tested this in the xquery sandbox and it works):

for $movie in doc("movies/movies.xml")/movies/movie[year > 2002]
    return <movie> { ($movie/title, $movie/year) } </movie>

How do I pass this in a URL? I dont really know where to start so I've tried just pasting the query above as the GET param, similar to the xpath query. So the url I pass is

http://localhost:8080/exist/rest/db/movies/?_query=for%20$movie%20in%20doc(%22movies/movies.xml%22)/movies/movie[year%20%3E%202002]%20return%20%3Cmovie%3E%20{%20($movie/title,%20$movie/year)%20}%20%3C/movie%3E

The page I get back is this 页面回复

Am I going about this totally the wrong way? "movies" is a collection in my db. 在此输入图像描述

It looks like your query was successfully executed. The <exist:result/> element looks quite correct, but it simply didn't find any movies which fit your filter criteria. It might also be a namespace issue. You should try your query locally to see if it returns something.

Your <script id="tinyhippos-injected"/> element is rather weird, as I did not expect tiny hippos here. However, this seems to be due to some Chrome extension you use .

Also, if your XQuery is a bit longer a URL paramter will not do and the encoding is difficult to read and maintain anyways. You might want to take a look at the eXist documentation about how to submit a POST request with an XQuery .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM