简体   繁体   English

eXist-db从同一集合的许多XML中获取数据

[英]eXist-db getting data from many XMLs of the same collection

I'm new to using eXist-db. 我是使用eXist-db的新手。 Using Java/Groovy I am trying (with no luck) to get data from a collection I created: /db/apps/compositions . 我正在尝试使用Java / Groovy(没有运气)从我创建的集合中获取数据: /db/apps/compositions

In /db/apps/compositions are a couple of XML documents that look similar to this: /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>

I am using the XQJ API in my client side code. 我在客户端代码中使用XQJ API。 I tried to adapt the example code (from http://en.wikipedia.org/wiki/XQuery_API_for_Java and http://xqj.net/exist/ ): 我试图改编示例代码(来自http://en.wikipedia.org/wiki/XQuery_API_for_Javahttp://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();

I expected to get the xxxxx texts from all the XML Document in the /db/apps/compositions collection but I get no results and no exceptions are thrown. 我希望从/db/apps/compositions集合中的所有XML文档中获取xxxxx文本,但是没有任何结果,也不会引发任何异常。

Any ideas? 有任何想法吗?

Thanks a lot! 非常感谢!

BTW: I tried to find other ways of implementing a java client, but couldn't find a clear guideline or tutorial for beginners. 顺便说一句:我试图找到其他实现Java客户端的方法,但是找不到适合初学者的明确指南或教程。

The problem you have is all about namespaces; 您所遇到的问题全都与名称空间有关。 your element is in default namespace so you need to define that namespace in your query. 您的元素位于默认名称空间中,因此您需要在查询中定义该名称空间。

xquery version "3.0";

declare default element namespace "http://schemas.openehr.org/v1";

for $n in fn:collection('/db/apps/compositions')//data

return fn:data($n/name/value)

read more in eg the tech wiki 阅读更多信息,例如技术维基

In general I'd recommend to test queries in the the excellent eXide IDE first before merging them into code. 通常,我建议先在出色的eXide IDE中测试查询,然后再将其合并到代码中。 The IDE provides you fast feedback on query results so you can play a bit with your queries. IDE为您提供有关查询结果的快速反馈,因此您可以轻松地进行查询。

Note that writing 注意写作

*:data

might slowdown queries on large datasets. 可能会减慢对大型数据集的查询。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM