MarkLogicJavaAPI-如何获取文档

MarkLogicJavaAPI-如何获取文档,marklogic,Marklogic,目前,我正在尝试使用JavaAPI从MarkLogic服务器获取数据(XML) 因此,我添加了名称空间: NamespacesManager nsManager = client.newServerConfigManager() .newNamespacesManager(); nsManager.addPrefix("document", "http://test/dummy/master/doc"); ... 之后,我尝试了以下几点: DatabaseClient client =

目前,我正在尝试使用JavaAPI从MarkLogic服务器获取数据(XML)

因此,我添加了名称空间:

NamespacesManager nsManager = client.newServerConfigManager()
  .newNamespacesManager();
nsManager.addPrefix("document",
  "http://test/dummy/master/doc");
...
之后,我尝试了以下几点:

DatabaseClient client = DatabaseClientFactory.newClient("IP_ADDRESS",
  PORT, user, password, Authentication.DIGEST);

SearchHandle handle = new SearchHandle();
QueryManager queryMgr = client.newQueryManager();

KeyValueQueryDefinition query = queryMgr.newKeyValueDefinition();
query.put(
  queryMgr.newElementLocator(new QName("doc:id")),
  "1439-1074");
SearchHandle resultsHandle = queryMgr.search(query, handle);
System.out.println("results: " + resultsHandle.getTotalResults());

// System.out.println("Matched "+resultsHandle.getTotalResults()+
// " documents with '"+query.getCriteria()+"'\n");

// iterate over the result documents
MatchDocumentSummary[] docSummaries = resultsHandle.getMatchResults();
System.out.println("Listing "+docSummaries.length+" documents:\n");
所有工程;我得到了结果,但它们不包含XML文档(只包含文档的URI)。是否可以通过此查询获得XML结果,或者我是否必须提交第二个查询,如:

JSONDocumentManager docMgr = client.newJSONDocumentManager();
StringHandle doc = docMgr.read(uri, new StringHandle());

您必须使用与所需结果匹配的结果句柄。看一看

不要使用
SearchHandle
,而是使用
StringHandle
。以下是文档示例:

// create a handle for the search results to be received as raw XML
StringHandle resultsHandle = new StringHandle();
// run the search
queryMgr.search(query, resultsHandle);
// dump the XML results to the console
System.out.println(resultsHandle);

要取回整个文档而不是片段,请指定 原始转换结果将显示在查询选项中:

<transform-results apply="raw" />
如果文档是XML,则可能需要使用内置的XML解析句柄,例如 DOMHandle、SAXHandle或XMLStreamReaderHandle(或 JDOMHandle或XOMHandle示例)而不是SearchHandle和extract 来自响应负载的文档

如果文档是JSON,您可能希望使用
JacksonHandle示例。

如何添加该示例?我尝试了以下内容:stringoptions=“”;StringHandle=新的StringHandle(选项);但是结果没有改变..String options=“感谢您的响应,但是仅仅改变结果句柄并不能解决我的问题。结果是一样的(数据只包含URI)。
http://docs.marklogic.com/guide/search-dev/search-api#id_58295