gpt4 book ai didi

java - 如何从java查询eXist数据库

转载 作者:行者123 更新时间:2023-12-01 14:44:30 28 4
gpt4 key购买 nike


我正在尝试基于 eXist 数据库查询文件。
通过简单的函数来显示文件内容,没问题:

XMLResource res = (XMLResource) col.getResource(resourceName); 
System.out.println(res.getContent());


但是当我试图阻止请求变得不可能时。

String xQuery = "for $x in doc(\"" + resourceName + "\")." + "return data($x).";
ResourceSet result = service.query(xQuery);
ResourceIterator i = result.getIterator();



我有以下错误:

Exception in thread "main" org.xmldb.api.base.XMLDBException: Failed to invoke method queryP in class org.exist.xmlrpc.RpcConnection: org.exist.xquery.StaticXQueryException: exerr:ERROR org.exist.xquery.XPathException: exerr:ERROR err:XPST0003 in line 1, column 58: unexpected token: .

at org.exist.xmldb.RemoteXPathQueryService.query(RemoteXPathQueryService.java:114)
at org.exist.xmldb.RemoteXPathQueryService.query(RemoteXPathQueryService.java:71)
at ExistAccess.main(ExistAccess.java:45)
Caused by: org.apache.xmlrpc.XmlRpcException: Failed to invoke method queryP in class org.exist.xmlrpc.RpcConnection: org.exist.xquery.StaticXQueryException: exerr:ERROR org.exist.xquery.XPathException: exerr:ERROR err:XPST0003 in line 1, column 58: unexpected token: .

at org.apache.xmlrpc.client.XmlRpcStreamTransport.readResponse(XmlRpcStreamTransport.java:197)
at org.apache.xmlrpc.client.XmlRpcStreamTransport.sendRequest(XmlRpcStreamTransport.java:156)
at org.apache.xmlrpc.client.XmlRpcHttpTransport.sendRequest(XmlRpcHttpTransport.java:143)
at org.apache.xmlrpc.client.XmlRpcSunHttpTransport.sendRequest(XmlRpcSunHttpTransport.java:69)
at org.apache.xmlrpc.client.XmlRpcClientWorker.execute(XmlRpcClientWorker.java:56)
at org.apache.xmlrpc.client.XmlRpcClient.execute(XmlRpcClient.java:167)
at org.apache.xmlrpc.client.XmlRpcClient.execute(XmlRpcClient.java:158)
at org.apache.xmlrpc.client.XmlRpcClient.execute(XmlRpcClient.java:147)
at org.exist.xmldb.RemoteXPathQueryService.query(RemoteXPathQueryService.java:99)
... 2 more
[B@105081caorg.apache.xmlrpc.XmlRpcException: Failed to invoke method queryP in class org.exist.xmlrpc.RpcConnection: org.exist.xquery.StaticXQueryException: exerr:ERROR org.exist.xquery.XPathException: exerr:ERROR err:XPST0003 in line 1, column 58: unexpected token: .



我检查了我所有的 .jar 文件,它们都存在......我真的需要帮助!提前致谢!

最佳答案

您的查询:

String xQuery = "for $x in doc(\"" + resourceName + "\")." + "return data($x).";

错误的核心:

err:XPST0003 in line 1, column 58: unexpected token: .

正如错误消息所述,eXist-db 识别出带有“.”的错误;该句点/点是无效的 XQuery。从查询中删除点,你应该没问题。查询文本本身应如下所示:

for $x in doc("/db/mycollection/mydocument.xml") return data($x)

此外,您的 FLWOR 循环似乎正在迭代单个项目 - 资源。因此,FLWOR 是无关的。您可以将其重构为:

data(doc("/db/mycollection/mydocument.xml"))

关于java - 如何从java查询eXist数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15583170/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com