我創建了Xdbc數據庫連接並運行了成功的示例程序。 我已經創建markLogics.java
類和進口的jar文件marklogic-xcc-4.0.1.jar
獲取「XQueryException」,意外的標記語法錯誤
代碼快照:當執行代碼
package com.marklogic;
import java.net.URI;
import java.net.URISyntaxException;
import com.marklogic.xcc.ContentSource;
import com.marklogic.xcc.ContentSourceFactory;
import com.marklogic.xcc.Session;
import com.marklogic.xcc.Request;
import com.marklogic.xcc.ResultSequence;
import com.marklogic.xcc.exceptions.RequestException;
import com.marklogic.xcc.exceptions.XccConfigException;**
class markLogics {
public static void main(String args[]) throws XccConfigException,
RequestException {
URI uri = null;
try {
uri = new URI("xcc://user:[email protected]:8008/Marklogics");
// uri=new URI("");
} catch (URISyntaxException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String queryResult = "";
ContentSource contentSource = ContentSourceFactory
.newContentSource(uri);
Session session = contentSource.newSession();
String queryStr = "let $uri := xdmp:get-request-field(\"uri\")"
+ "return"
+ "if (empty($uri) or $uri eq\"\") then"
+ "("
+ " xdmp:set-response-content-type(\"\text/html\"),"
+ "<ul>"
+ "{for $i in collection()"
+ "let $doc := document-uri($i) return"
+ "<li>"
+ "<a href="
+ "\"view.xqy?uri={xdmp:url-encode($doc)}\""
+ " >{$doc}</a></li>"
+ "}</ul>)"
+ "else ( xdmp:set-response-content-type(\"text/xml\"), if (empty(doc($uri)))"
+ "then <error>No content" + "</error> else doc($uri) )";
// String
// queryStr="let $uri := xdmp:get-request-field(\"uri\")for $v in $doc//uri $a in $doc//play";
Request request = session.newAdhocQuery(queryStr);
try {
ResultSequence rs = session.submitRequest(request);
System.out.println(rs.asString());
} catch (Exception e) {
e.printStackTrace();
}
session.close();
}
}
,我得到異常:
com.marklogic.xcc.exceptions.XQueryException: XDMP-UNEXPECTED: (err:XPST0003) Unexpected token syntax error, unexpected QName_on line 1
expr:
at com.marklogic.xcc.impl.handlers.ServerExceptionHandler.handleResponse(ServerExceptionHandler.java:31)
at com.marklogic.xcc.impl.handlers.EvalRequestController.serverDialog(EvalRequestController.java:68)
at com.marklogic.xcc.impl.handlers.AbstractRequestController.runRequest(AbstractRequestController.java:72)
at com.marklogic.xcc.impl.SessionImpl.submitRequest(SessionImpl.java:280)
at com.marklogic.markLogics.main(test.java:34)
瞭解:
根據我在查詢中的理解,我已致電使用拋出異常的view.xqy
文件。
方法跟隨: 我試過以下方法來解決這個問題,將view.xqy
歸檔並添加到項目的構建路徑中,但它並沒有幫助我。
你能給我一些指導來克服打嗝嗎?