Loading TOC...

xdmp.multipartDecode

xdmp.multipartDecode(
   $separator as String,
   $data as binary(),
   [$options as Node]
) as Sequence

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.zipGet - 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

var html = fn.head(xdmp.unquote(
	       '<html><p>Some stuff in an .html document</p></html>'));
var xml = fn.head(xdmp.unquote('<root> \n\
                          <a>Some other stuff in a .xml document</a> \n\
                        </root>'));
var json = xdmp.toJSON(["a",false]);
var boundaryString = "gc0p4Jq0M2Yt08jU534c0p";
var manifest = fn.head(xdmp.unquote(
  '<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>')).root;
var mpe = xdmp.multipartEncode(
   boundaryString,
   manifest,
   [xml,html,json] );
xdmp.multipartDecode(boundaryString, mpe);
=>
[
  {
    "headers": {
                 "Content-Type": "application/xml",
                 "boundary": "gc0p4Jq0M2Yt08jU534c0p",
                 "Content-Length": "148"
               }
  },
  {
    "headers": {
                 "Content-Type": "text/html",
                 "Content-Length": "90"
               }
  },
  {
    "headers": {
                 "Content-Type": "application/json",
                 "Content-Length": "12"
               }
  }
]
<?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]

Stack Overflow iconStack Overflow: Get the most useful answers to questions from the MarkLogic community, or ask your own question.