我是使用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