我是使用eXist-db的新手。使用Java/Groovy我想(沒有運氣)從我創建的集合中獲取數據:/db/apps/compositions
。eXist-db從同一集合中的很多XML獲取數據
在/db/apps/compositions
是一對情侶,看起來類似於此XML文檔:
<version xmlns="http://schemas.openehr.org/v1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ORIGINAL_VERSION">
...
<data xsi:type="COMPOSITION" archetype_node_id="openEHR-EHR-COMPOSITION.signos.v1">
<name>
<value>xxxxx</value>
</name>
...
</data>
</version>
我用我的客戶端代碼的XQJ API。我試着(從http://en.wikipedia.org/wiki/XQuery_API_for_Java和http://xqj.net/exist/)適應示例代碼:
XQDataSource xqs = new ExistXQDataSource();
xqs.setProperty("serverName", "localhost");
xqs.setProperty("port", "8080");
XQConnection conn = xqs.getConnection("user","pass");
XQExpression expr = conn.createExpression();
XQResultSequence result = expr.executeQuery(
"for $n in fn:collection('/db/apps/compositions')//data " +
"return fn:data($n/name/value)"); // execute an XQuery expression
// Process the result sequence iteratively
while (result.next()) {
// Print the current item in the sequence
System.out.println("Product name: " + result.getItemAsString(null));
}
// Free all resources created by the connection
conn.close();
我預期從/db/apps/compositions
集合中的所有XML文檔得到xxxxx的文本,但我沒有得到任何結果,並沒有異常拋出。
任何想法?
非常感謝!
順便說一句:我試圖找到其他實現java客戶端的方法,但找不到明確的指導方針或初學者教程。
'data'元素屬於'version'聲明的默認名稱空間。你可以在你的代碼中引入這個命名空間,或者通過編寫'*:data'來通配符。 – 2014-11-24 09:07:14
如果您正在尋找Java客戶端示例,eXist書籍將整個「第13章 - 集成」全部用於查看選項並使用Java編寫客戶端:http://shop.oreilly.com/product/0636920026525.do 這本書應該在下個月印刷。然而,與此同時,集成章節(包括XQJ)的代碼示例可以在這裏找到:https://github.com/eXist-book/book-code/tree/master/chapters/integration – adamretter 2014-11-24 11:46:27