0


我正在尝试基于 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 文件,它们都存在……我真的需要帮助!提前致谢!

4

2 回答 2

1

您的查询:

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"))
于 2013-03-24T15:21:21.310 回答
0

我认为您的字符串 concat 会导致此问题,为什么不尝试在“。”之后添加一个空格。更改您的代码,例如

    String xQuery = "for $x in doc(\"" + resourceName + "\"). " + "return data($x).";
于 2013-03-23T05:34:05.137 回答