简体   繁体   English

如何通过eXist-db的REST api传递xquery?

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

I understand how to use Xpath 我理解如何使用Xpath

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

But how to pass an xquery query? 但是如何传递xquery查询? I keep reading everywhere that the REST api is for both xpath and xquery but I can't get my query to work. 我一直在阅读REST api适用于xpath和xquery,但我无法让我的查询工作。 Here is what I'm trying to pass as an example (I've tested this in the xquery sandbox and it works): 这是我试图传递的例子(我在xquery沙箱中测试了它并且它可以工作):

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? 如何在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. 我真的不知道从哪里开始,所以我尝试将上面的查询粘贴为GET参数,类似于xpath查询。 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. <exist:result/>元素看起来非常正确,但它根本找不到符合您的过滤条件的电影。 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. 你的<script id="tinyhippos-injected"/>元素相当奇怪,因为我没想到这里有<script id="tinyhippos-injected"/> However, this seems to be due to some Chrome extension you use . 但是,这似乎是由于您使用的某些Chrome扩展程序

Also, if your XQuery is a bit longer a URL paramter will not do and the encoding is difficult to read and maintain anyways. 此外,如果您的XQuery有点长,则URL参数不会执行,并且编码很难读取和维护。 You might want to take a look at the eXist documentation about how to submit a POST request with an XQuery . 您可能希望查看有关如何使用XQuery提交POST请求的eXist文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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