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

230 views Asked by At

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

There are 1 answers

2
ehennum On

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,