Loading TOC...

MarkLogic 10 Product Documentation
xdmp.multipartEncode

xdmp.multipartEncode(
   separator as String,
   manifest as Array|Node,
   content as Array|Sequence
) as binary()

Summary

Create a multipart encoding of the specified node. The returned binary node can be passed to xdmp.httpPost. The manifest is modeled after the manifest that is passed to xdmp.zipCreate, with the headers element being the same as is described for xdmp.httpGet allowing users to add arbitrary headers to each part. If a content-type header is not specified for a part, it will be determined if possible from the content.

There should be one part element for each node in the content sequence.

Each part also has an optional options node to control how xml or text will be serialized. The two options are the same as for xdmp.save.

<part>
    <headers>
      <Content-Type>image/jpeg</Content-Type>
    <headers>
    <options>
      <output-encoding>...</output-encoding>
      <output-sgml-character-entities>...</output-sgml-character-entities>
    </options>
  </part>

The manifest can also be defined as a JSON array.

[
    {
      "headers": {
        "Content-Type":"image/jpeg"
      },
      "options": {
       "outputEncoding": ...,
       "outputSgmlCharacterEntities" : ...
      }
    },
    {
      "headers": {
        "Content-Type":"text/html"
      }
    }
  ]

Parameters
separator The string that is to be used as a separator.
manifest The manifest.
content The nodes that are to be encoded.

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;
xdmp.multipartEncode(
   boundaryString,
   manifest,
   [xml,html,json] );

=>
--gc0p4Jq0M2Yt08jU534c0p
Content-Type: application/xml
boundary: gc0p4Jq0M2Yt08jU534c0p
Content-Length: 94

<?xml version="1.0" encoding="UTF-8"?>
<root><a>Some other stuff in a .xml document</a></root>
--gc0p4Jq0M2Yt08jU534c0p
Content-Type: text/html
Content-Length: 90

<?xml version="1.0" encoding="UTF-8"?>
<html><p>Some stuff in an .html document</p></html>
--gc0p4Jq0M2Yt08jU534c0p
Content-Type: application/json
Content-Length: 12

["a", false]
--gc0p4Jq0M2Yt08jU534c0p--

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_json = [
  {
    "headers": {
      "Content-Type":"application/xml",
      "boundary":"gc0p4Jq0M2Yt08jU534c0p"
    }
    ,
    "options": {
     "outputEncoding": "utf-8",
     "outputSgmlCharacterEntities" : false
    }
  },
  {
    "headers": {
      "Content-Type":"text/html"
    }
  },
    {
    "headers": {
      "Content-Type":"application/json"
    }
  }
];
xdmp.multipartEncode(
   boundaryString,
   manifest_json,
   [xml,html,json] );

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