我正在尝试基于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文件,所有人都在场......我真的需要帮助!提前谢谢!
答案 0 :(得分: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"))
答案 1 :(得分:0)
我认为你的字符串concat使这个问题,为什么不尝试在“。”之后添加一个空格。更改您的代码,如
String xQuery = "for $x in doc(\"" + resourceName + "\"). " + "return data($x).";