How to transform multiple documents into a single document using MarkLogic's REST API?

空扰寡人 提交于 2019-12-11 03:49:50

问题


Using MarkLogic REST API, when I set Accept to multipart/mixed I see the response in the format:

--BOUNDARY
    Content-Type: application/xml
    Content-Disposition: attachment; filename="/hcp/458.xml"; category=content; format=xml
    Content-Length: 412

<?xml version="1.0" encoding="UTF-8"?>
<hcp xmlns="http://schemas.com">
  <id>458</id>
  <tenantId>2</tenantId>
  <firstName>Hoongoong</firstName>
  <middleName/>
  <lastName>Tangyy</lastName>      
</hcp>
--BOUNDARY
Content-Type: application/xml
Content-Disposition: attachment; filename="/hcp/2.xml"; category=content; format=xml
Content-Length: 409

<?xml version="1.0" encoding="UTF-8"?>
<hcp xmlns="http://schemas.com">
  <id>2</id>
  <tenantId>3</tenantId>
  <firstName>Hoong</firstName>
  <middleName>F</middleName>
  <lastName>Tang</lastName>     
</hcp>
--BOUNDARY

Is there a way via some tweak or applying transformation to display the result as a single document (containing documents as child element) instead of multiple documents separated by boundary?

<results>
   <hcp>
      <id>458</id>
       .....
    </hcp>
   <hcp>
      <id>2</id>
     ......
   </hcp>
</results>

回答1:


You can execute a search with the REST API, setting the Accept header to application/xml.

Specify an extract-document-data option of all to get the entire documents.

http://docs.marklogic.com/guide/rest-dev/appendixb#id_18313

You can use a document-query if you just need to list specific documents:

http://docs.marklogic.com/guide/search-dev/structured-query#id_27172

You can also transform the search response on the server:

http://docs.marklogic.com/guide/rest-dev/search#id_94556

Hoping that helps,



来源:https://stackoverflow.com/questions/30733248/how-to-transform-multiple-documents-into-a-single-document-using-marklogics-res

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!