MarkLogic 10 Product Documentation
xdmp:multipart-decode

xdmp:multipart-decode(
   $separator as xs:string,
   $data as binary(),
   [$options as element()]
) as node()*

Summary

Extract the parts from a multipart encoding. The first item in the sequence is a manifest, and the remaining items are the decoded parts.

An attempt will be made to determine the type of content based on headers such as the part's content-type. If possible, an element will be returned, falling back to an xs:string, and finally binary().

The options control how the parts are unpacked, and are similar to xdmp:zip-get - default-namespace, repair, format, default-language, and encoding. The options apply to all parts, so specifying a format of binary will cause all parts to be returned as binary, and specifying text will cause all parts to be returned as xs:string if possible, falling back to binary() if necessary. This is useful if different parts need different options, in which case the resulting strings can each be passed to xdmp:unquote with appropriate options.

Parameters
separator The string that is to be used as a separator.
data The data (as a binary node) to be decoded.
options Decode options.

Example

xquery version "1.0-ml";
let $html := document{ <html><p>Some stuff in an .html document</p></html> }
let $xml := document{ <root><a>Some other stuff in a .xml document</a></root> }
let $json := xdmp:to-json(("a",fn:false()))
let $boundary-string := "gc0p4Jq0M2Yt08jU534c0p"
let $mpe := xdmp:multipart-encode(
   $boundary-string,
   <manifest>
     <part>
       <headers>
         <Content-Type>application/xml</Content-Type>
         <boundary>gc0p4Jq0M2Yt08jU534c0p</boundary>
       </headers>
     </part>
     <part>
       <headers>
         <Content-Type>text/html</Content-Type>
       </headers>
      </part>
     <part>
       <headers>
         <Content-Type>application/json</Content-Type>
       </headers>
     </part>
   </manifest>,
   ($xml,$html,$json) )
return xdmp:multipart-decode($boundary-string, $mpe)
=>
<manifest>
  <part>
    <headers>
      <Content-Type>application/xml</Content-Type>
      <boundary>gc0p4Jq0M2Yt08jU534c0p</boundary>
      <Content-Length>94</Content-Length>
    </headers>
  </part>
  <part>
    <headers>
      <Content-Type>text/html</Content-Type>
      <Content-Length>90</Content-Length>
    </headers>
  </part>
  <part>
    <headers>
      <Content-Type>application/json</Content-Type>
      <Content-Length>12</Content-Length>
    </headers>
  </part>
</manifest>
<?xml version="1.0" encoding="UTF-8"?>
<root><a>Some other stuff in a .xml document</a></root>
<?xml version="1.0" encoding="UTF-8"?>
<html><p>Some stuff in an .html document</p></html>
["a", false]

Powered by MarkLogic Server | Terms of Use | Privacy Policy